Fascinating! I do use parser combinators myself, and find myself having to use the eta-expanded form, like you say. Thanks for that explanation.
Mark. on 10/11/10 2:20 PM, Jon Harrop <jonathandeanhar...@googlemail.com> wrote: > In OCaml, the value restriction leads to non-generalized type variables ('_a > etc.) if you try to define functions like: > > # let ( << ) f g x = f(g x);; > val ( << ) : ('a -> 'b) -> ('c -> 'a) -> 'c -> 'b = <fun> > > # let cons h t = h::t;; > val cons : 'a -> 'a list -> 'a list = <fun> > > # cons << cons;; > - : '_a -> ('_a list -> '_a list) list -> ('_a list -> '_a list) list = > <fun> > > This is a silly example but you are most likely to hit this problem in > practice in the context of parser combinators. Due to JIT compilation, F# > cannot relax the value restriction so that does not even compile. > > In MLs, you usually want the eta-expanded form: > > # let cons2 x = (cons << cons) x;; > val cons2 : 'a -> ('a list -> 'a list) list -> ('a list -> 'a list) list = > <fun> > > But a pipeline is prettier: > > # let ( |> ) x f = f x;; > val ( |> ) : 'a -> ('a -> 'b) -> 'b = <fun> > > # let cons2 x = x |> cons |> cons;; > val cons2 : 'a -> ('a list -> 'a list) list -> ('a list -> 'a list) list = > <fun> > > This is one advantage of Haskell over OCaml/F#. However, I don't see it as a > useful advantage in practice because parser combinators are so tedious > during development (they require constant attention as types evolve): you > want code generation like ocamlyacc or camlp4. OCaml is a very strong > contender here, of course. > > Cheers, > Jon. > >> -----Original Message----- >> From: m...@proof-technologies.com [mailto:m...@proof-technologies.com] >> Sent: 10 November 2010 13:44 >> To: jonathandeanhar...@googlemail.com; ymin...@gmail.com; >> ar...@noblesamurai.com >> Cc: caml-l...@inria.fr >> Subject: Re: [Caml-list] Infix function composition operator >> >> So how does value restriction affect things here? (excuse my lack of >> knowledge) >> >> One thing about using a pipeline like this is that it relies on '|>' >> being >> left-associative (which it is due to OCaml's convention on operators >> that >> start with "|"). >> >> Mark. _______________________________________________ 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