From: brogoff <brogoff@speakeasy.net>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Factoring HOFs
Date: Fri, 1 Oct 2004 10:35:27 -0700 (PDT) [thread overview]
Message-ID: <Pine.LNX.4.58.0410011001500.24014@shell2.speakeasy.net> (raw)
In-Reply-To: <20041001.081752.59461685.garrigue@kurims.kyoto-u.ac.jp>
On Fri, 1 Oct 2004, Jacques Garrigue wrote:
> From: Keith Wansbrough <Keith.Wansbrough@cl.cam.ac.uk>
> >
> > 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
next prev parent reply other threads:[~2004-10-01 17:35 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-09-25 21:12 [Caml-list] C++ STL and template features compared with OCaml parametric polymorphism and OO features Vasili Galchin
2004-09-25 21:38 ` Nicolas Cannasse
2004-09-25 22:15 ` Vasili Galchin
2004-09-25 22:52 ` Vasili Galchin
2004-09-26 1:34 ` Jon Harrop
2004-09-26 5:31 ` Radu Grigore
2004-09-26 9:47 ` sejourne_kevin
2004-09-26 13:05 ` Jon Harrop
2004-09-26 14:36 ` skaller
2004-09-26 15:08 ` sejourne_kevin
2004-09-26 15:27 ` skaller
2004-09-26 18:51 ` Jon Harrop
2004-09-26 20:14 ` Radu Grigore
2004-09-27 1:59 ` Jon Harrop
2004-09-27 4:48 ` skaller
2004-09-27 9:40 ` Jacques GARRIGUE
2004-09-27 10:50 ` Radu Grigore
2004-09-27 12:14 ` skaller
2004-09-27 13:11 ` Jon Harrop
2004-09-27 13:31 ` Radu Grigore
2004-09-27 16:54 ` Jon Harrop
2004-09-29 18:59 ` Radu Grigore
2004-09-27 13:32 ` Radu Grigore
2004-09-27 14:04 ` Brian Hurt
2004-09-27 14:58 ` skaller
2004-09-27 15:30 ` Brian Hurt
2004-09-27 16:38 ` skaller
2004-09-27 17:01 ` Brian Hurt
2004-09-28 1:21 ` skaller
2004-09-27 16:41 ` brogoff
2004-09-28 0:26 ` skaller
2004-09-29 15:32 ` Florian Hars
2004-09-29 16:49 ` [Caml-list] Factoring HOFs [was Re: C++ STL...] Jon Harrop
2004-09-30 9:19 ` Radu Grigore
2004-09-30 10:13 ` Keith Wansbrough
2004-09-30 10:31 ` Keith Wansbrough
2004-09-30 13:21 ` skaller
2004-09-30 23:17 ` [Caml-list] Factoring HOFs Jacques Garrigue
2004-10-01 8:46 ` Keith Wansbrough
2004-10-01 17:35 ` brogoff [this message]
2004-09-26 20:43 ` [Caml-list] C++ STL and template features compared with OCaml parametric polymorphism and OO features skaller
2004-09-26 14:19 ` skaller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.58.0410011001500.24014@shell2.speakeasy.net \
--to=brogoff@speakeasy.net \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox