caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] strange match error
@ 2002-03-11 22:33 Jeff Polakow
  2002-03-11 23:35 ` Johan Georg Granström
  0 siblings, 1 reply; 2+ messages in thread
From: Jeff Polakow @ 2002-03-11 22:33 UTC (permalink / raw)
  To: caml-list

Hello,

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?

thanks,
  Jeff
-------------------
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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Caml-list] strange match error
  2002-03-11 22:33 [Caml-list] strange match error Jeff Polakow
@ 2002-03-11 23:35 ` Johan Georg Granström
  0 siblings, 0 replies; 2+ messages in thread
From: Johan Georg Granström @ 2002-03-11 23:35 UTC (permalink / raw)
  To: Jeff Polakow; +Cc: caml-list

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-03-11 23:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-03-11 22:33 [Caml-list] strange match error Jeff Polakow
2002-03-11 23:35 ` Johan Georg Granström

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).