Le mardi 06 octobre 2009 à 14:01 +0200, Chantal KELLER a écrit :
> Dear Ocaml users,
> 
>   Is there a reason for constructors not to behave like functions? For
> instance, one cannot make a partial application from a constructor:
> 
> # type foo = | Bar of int;;
> type foo = Bar of int
> # let foobar = Bar in foobar 17;;
> Error: The constructor Bar expects 1 argument(s),
>        but is applied here to 0 argument(s)

This does not answer the question, but you can have function generated
automatically for constructors using camlp4.

I wrote some time ago an extension which add a type-conv type processor
"constructor", so you can write:

  type t = Foo of string | Bar of int * int
    with constructor

and it automatically generates these two functions:

  val foo : string -> t
  val bar : int -> int -> t

The extension is available here:
http://darcs.ocamlcore.org/cgi-bin/darcsweb.cgi?r=obus;a=headblob;f=/syntax/pa_constructor.ml

-- 
Jérémie

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Reply via email to