From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id TAA01675; Fri, 1 Oct 2004 19:35:32 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id TAA01884 for ; Fri, 1 Oct 2004 19:35:31 +0200 (MET DST) Received: from mail1.speakeasy.net (mail1.speakeasy.net [216.254.0.201]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id i91HZS4W005438 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 1 Oct 2004 19:35:30 +0200 Received: (qmail 17112 invoked from network); 1 Oct 2004 17:35:27 -0000 Received: from shell2.speakeasy.net ([69.17.110.71]) (envelope-sender ) by mail1.speakeasy.net (qmail-ldap-1.03) with AES256-SHA encrypted SMTP for ; 1 Oct 2004 17:35:27 -0000 Date: Fri, 1 Oct 2004 10:35:27 -0700 (PDT) From: brogoff To: caml-list@inria.fr Subject: Re: [Caml-list] Factoring HOFs In-Reply-To: <20041001.081752.59461685.garrigue@kurims.kyoto-u.ac.jp> Message-ID: References: <200409291749.17226.jon@jdh30.plus.com> <20041001.081752.59461685.garrigue@kurims.kyoto-u.ac.jp> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Miltered: at concorde with ID 415D9560.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; brogoff:01 brogoff:01 caml-list:01 hofs:01 jacques:01 quantifiers:01 simonpj:01 quantifiers:01 verbose:01 infer:01 okasaki's:01 annotations:01 functor:01 haskell:01 val:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Fri, 1 Oct 2004, Jacques Garrigue wrote: > From: Keith Wansbrough > > > > but OCaml doesn't allow nested quantifiers (i.e., higher-rank > > polymorphism). > > > > It actually wouldn't be very hard to support, if you're prepared to > > accept the need for the occasional type annotation - see > > http://research.microsoft.com/~simonpj/papers/putting/index.htm. > > OCaml has been supporting nested quantifiers for years. > However, they are a little more verbose because we chose to allow > unpredicate 2nd order types, which are harder to infer. > > Look in the manual for polymorphic record fields and polymorphic > methods. The former are lighter syntactically, but require an > explicit record definition in advance, while the latter allow defining > polymorphic values on the fly. These are good additions to the language which allow you to do lots of things, like encode Okasaki's algorithms more directly, but they don't seem like a satisfactory solution. It would be better to just have the user give a type annotation on functions I think. Also for recursive types, it seems like it would better to allow them in the language with explicit annotations rather than having a compiler switch or having to wrap in constructors. > But your example also uses constructor variables, which are not > available in ocaml. Note however that you can still encode it using > a functor: Nice. Xavier Leroy used a similar encoding a while back to simulate higher order type constructors. This trick seems FAQworthy. It's funny, because I read some paper by Haskell guys talking about how the ML module system is powerful but overcomplex (hope I'm not misstating the intent of the paper!) yet it seems more intuitive than type classes to me. -- Brian > module Map2(M : sig type 'a f val map : ('a -> 'b) -> 'a f -> 'b f end) = > struct > let map2 g f x = M.map g (M.map f x) > end > > Not much longer, he? > You can apply this functor locally with "let module". > > let to_string l = > let module M = Map2(struct type 'a f = 'a list let map = List.map end) in > M.map2 string_of_int (fun x -> x + 1) l > > Jacques > > ------------------- > 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 > ------------------- 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