From: "Daniel Bünzli" <daniel.buenzli@erratique.ch>
To: Gabriel Scherer <gabriel.scherer@gmail.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] List.fold_left vs. Hashtbl.fold
Date: Fri, 30 Nov 2012 17:48:21 +0100 [thread overview]
Message-ID: <E38AD5F50E9645C99D66BD3BAAA5B984@erratique.ch> (raw)
In-Reply-To: <CAPFanBHUR6Dfnwz=45ojgA-bR5nv6tYSwz_+hEqN6YnMvUbkgw@mail.gmail.com>
Le vendredi, 30 novembre 2012 à 17:00, Gabriel Scherer a écrit :
> I don't know. "function application is just space" is indeed a
> convenient syntax to emulate other syntaxes (for example embed a
> concatenative language through cunning continuation-passing-style),
My concern is not really about the syntax.
> but that doesn't need to go away with non-currified functions, which
> is about applying all arguments, not necessarily forcing a tupled
> syntax.
That's the point, currying allows you to build a function incrementally with things happening between each applied argument.
This is for example very useful to meta-program other languages from OCaml (using the abstraction mechanisms and variable binders of OCaml itself). It may not be very clear (the whole program is not here, if you are interested I can mail you the whole example), but with the combinators given at the end of this message, I'm able to gradually construct a program representing a function in another language, with an arbitrary number of arguments, compile it, and then get it as regular OCaml function (Program.as_fun) that uses OCaml gound types and that can be passed around completely hiding that the function may actually not be executed by OCaml at all.
Currying gives you glue, I'm not sure you could do these kind of things without it. If you can't then currying is not overrated to me. See also http://mlton.org/Fold
Best,
Daniel
type 'a exp (* expressions constructed with combinators *)
module Program : sig
type 'a t
type ('a, 'b, 'c) stage (* b is the type of the constructed function *)
(* Note. The types enforces that only caml functions from 'a exp(s) to
'a exp will be accepted for compilation into a program. *)
val retb : ('a exp -> 'b) -> ('a exp -> 'b, bool , [`Bool ]) stage
val reti : ('a exp -> 'b) -> ('a exp -> 'b, int , [`Int ]) stage
val retf : ('a exp -> 'b) -> ('a exp -> 'b, float, [`Float]) stage
val argb : (bool_e -> 'a, 'b, 'c) stage -> ('a, bool -> 'b, 'c) stage
val argi : (int_e -> 'a, 'b, 'c) stage -> ('a, int -> 'b, 'c) stage
val argf : (float_e -> 'a, 'b, 'c) stage -> ('a, float -> 'b, 'c) stage
val compile : ('a exp, 'b, 'a) stage -> 'b t
val as_fun : 'a t -> 'a
val source : 'a t -> string
end
next prev parent reply other threads:[~2012-11-30 16:49 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-30 3:06 William Smith
2012-11-30 9:53 ` Gabriel Scherer
2012-11-30 10:06 ` Stefano Zacchiroli
2012-11-30 16:00 ` Gabriel Scherer
2012-11-30 16:48 ` Daniel Bünzli [this message]
2012-11-30 11:34 ` Daniel Bünzli
-- strict thread matches above, loose matches on Subject: below --
2012-11-28 4:40 William Smith
2012-11-28 16:17 ` Lukasz Stafiniak
2012-11-28 16:25 ` Malcolm Matalka
2012-11-28 16:21 ` David House
2012-11-29 1:06 ` Francois Berenger
2012-11-28 16:42 ` Oliver Bandel
2012-11-28 17:11 ` Adrien
2012-11-28 17:41 ` Virgile Prevosto
2012-11-29 0:07 ` Jacques Garrigue
[not found] ` <CAPFanBG04BiwJuPkV80__Ondmg1N8OEg4DokiXqDReg3ycNBdA@mail.gmail.com>
2012-11-28 17:25 ` Gabriel Scherer
2012-11-28 17:37 ` Lukasz Stafiniak
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=E38AD5F50E9645C99D66BD3BAAA5B984@erratique.ch \
--to=daniel.buenzli@erratique.ch \
--cc=caml-list@inria.fr \
--cc=gabriel.scherer@gmail.com \
/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