Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] strange match error
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Johan_Georg_Granström <georg.g@h...>
Subject: Re: [Caml-list] strange match error
Jeff,


> I ran into a strange (I think) error and was wondering if someone
> out there can help me out.
>
> Why does the following program:
>   type tt = A of string * int | B;;
>   let f x = print_string ((fst x)^"\n");;
>   let g x = match x with A y -> f y | B -> ();;
>
> produce the following response from ocaml?
>   # #use "caml_test.ml";;
>   type tt = A of string * int | B
>   val f : string * 'a -> unit = <fun>
>   File "caml_test.ml", line 3, characters 23-26:
>   The constructor A expects 2 argument(s), but is here applied to 1
> argument(s)
>
> Shouldn't the type reconstructor/checker realize that y is a pair?

Nope, since it isn't. Try
    type tt = A of (string * int) | B;;
if you want A to be of one argument, a pair.
The syntax is a bit obscure here...
In revised syntax, the first would read
    type tt = [A of string and int | B];
and the second
    type tt = [A of (string * int) | B];
which makes the difference much more clear.

Yours,

- Johan Granström

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners