I'm not 100% familiar with the object system, but you can write them on records. type 'a stream = { fold : 'b . ('a -> 'b -> 'b) -> 'b -> 'b } The reason that writing them here does not break inference is that the inference mechanism knows that it needs to insert the universally quantified type at the position of the record constructor, i.e. when it sees { foo = X } it knows that it should introduce the quantifier there. This makes it syntax-directed. On Mon, May 16, 2016 at 12:04 PM, Yotam Barnoy wrote: > Right, but they can't be inferred on objects and records either, and yet > they're allowed there... so what was the rationale? > > On Mon, May 16, 2016 at 2:53 PM, Gregory Malecha > wrote: > >> There may other reasons as well, e.g. performance and compilability, but >> the main reason that I know is that inferring these types is difficult >> (undecideable in general). For a point of comparison, GHC supports types >> like this, but only when they are explicitly written. >> >> On Mon, May 16, 2016, 11:50 AM Yotam Barnoy >> wrote: >> >>> Paging the type experts -- is there a concrete reason why we disallow >>> writing this type directly? >>> >>> On Mon, May 16, 2016 at 1:32 PM, Gerd Stolpmann >>> wrote: >>> >>>> Am Montag, den 16.05.2016, 17:55 +0100 schrieb Guillaume Hennequin: >>>> > Thanks all for your prompt answers; >>>> > >>>> > > See the FAQ entry, "How to write a function with polymorphic >>>> arguments?" >>>> > > >>>> https://ocaml.org/learn/faq.html#Howtowriteafunctionwithpolymorphicarguments >>>> > >>>> > this page explains how to do it with records or objects, but ends >>>> with a >>>> > mysterious "FIXME: a direct way now exists". Does anyone know what >>>> this might >>>> > refer to? >>>> >>>> What you would need is >>>> >>>> let print_both : ('a . 'a -> 'a) -> unit = ... >>>> >>>> i.e. the scope of the quantifier is restricted to the first argument. >>>> This doesn't exist to my knowledge. Maybe it was part of some dev >>>> version? >>>> >>>> Gerd >>>> -- >>>> ------------------------------------------------------------ >>>> Gerd Stolpmann, Darmstadt, Germany gerd@gerd-stolpmann.de >>>> My OCaml site: http://www.camlcity.org >>>> Contact details: http://www.camlcity.org/contact.html >>>> Company homepage: http://www.gerd-stolpmann.de >>>> ------------------------------------------------------------ >>>> >>>> >>> -- >> >> - gregory malecha >> gmalecha.github.io >> > > -- gregory malecha gmalecha.github.io