On Fri, Oct 29, 2010 at 5:37 PM, bluestorm <bluestorm.dylc@gmail.com> wrote:
On Fri, Oct 29, 2010 at 11:10 PM, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
> type _ t =
>   | IntLit : int -> int t
>   | BoolLit : bool -> bool t
>   | Pair : 'a t * 'b t -> ('a * 'b) t
>   | App : ('a -> 'b) t * 'a t -> 'b t
>   | Abs : ('a -> 'b) -> ('a -> 'b) t

> There's something "Haskellish" about this syntax, in the sense that type
> constructors are portrayed as being like functions.

Indeed IIRC OCaml does not accept "App" as an expression (you have to
provide arguments to the construct).  Maybe this is a good opportunity
to lift this restriction.

It was actually the case in Caml Light : each datatype constructor implicitly declared a constructor function with the same name. I don't exactly know why this feature was dropped in Objective Caml, but I think I remember (from a previous discussion) that people weren't sure it was worth the additional complexity.

Note that, as in Jacques's examples, the constructor function was not curryfied. (type t = A of bool * int) would generate a function (A : bool * int -> t). It doesn't help the already tricky confusion between (A of bool * int) and (A of (bool * int))...
By the way, it is unclear if
  | App : ('a -> 'b) t -> 'a t -> 'b t
would be accepted in Jacques proposal. If not, I think going back to a "of ..." syntax would be wiser.


It is accepted. In fact, that constructor is part of an example on my webpage. If there's any doubt, you can always download the source and try it out.
cheers,
Jacques

_______________________________________________
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