Version française
Home     About     Download     Resources     Contact us    
Browse thread
a problem about type recongnition
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: blue storm <bluestorm.dylc@g...>
Subject: Re: [Caml-list] a problem about type recongnition
You need parenthesis around (n+1), and it's "if m>first(element ) &&
n< second(element)" : "and" is an OCaml keyword.

There is a beginner list (
http://groups.yahoo.com/group/ocaml_beginners ) that would probably be
more suited to those questions.

On 2/22/09, Su Zhang <westlifezs@gmail.com> wrote:
> Hi all,
>
> I have a problem while executing ocaml, did you see any problem in my code?
> and do I need to give each variable a type before I use it ?my code is in
> the following, you can take a look at the code and the info of the errors
>
>
> let rec first(x, y, z)=x
>
> let rec second(x,y,z)=y
>
> let rec third(x,y,z)=z
>
>
>
> let rec rebuilt anss  (m,n,ys)= match anss with
>
>         []           ->       (m,n,ys)
>
> |element::anss ->
>
>          if m>first(element ) and n< second(element)
>
>          then rebuilt anss (m,n,ys)
>
>          else element::(rebuild anss (m,n,ys))
>
>
>
> let rec sum anss cur n ys= match cur with
>
>            None   ->
>
>              (match ys with
>
> []-> anss
>
> |y::ys->
>
> if y=0
>
> then sum(rebuild anss (n,n,0)) None n+1 ys
>
> else sum anss (Some(n, y, [y])) (n + 1) ys)
>
>
> the red area is shown has an error, and the error info is like this:"This
> expression has type int list -> 'a but is here used with type int", so would
> you please let me know if possible how can I let the compiler know the type
> of anss is a list but not an integrer?
>
> thank you
> --
> Su Zhang
> PHD Student
> Computer Information and Science
> Kansas State University
>