From: Elias Gabriel Amaral da Silva <tolkiendili@gmail.com>
To: ben kuin <benkuin@gmail.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] what do I need to know to understand camlp4
Date: Thu, 23 Sep 2010 21:15:00 -0300 [thread overview]
Message-ID: <AANLkTi=7TRCwxgRSPTOCN-1E0-KsWHzquLAoDhVaWAcb@mail.gmail.com> (raw)
In-Reply-To: <AANLkTinqvjrCvWdwcY9wM2G0tdrTiyKKjsUkhakcvx_u@mail.gmail.com>
2010/9/23 ben kuin <benkuin@gmail.com>:
>> [1] Compared to other programming languages. I know the syntax is > the way it is for precise reasons (currying, closer to mathematical
>> notation, ...).
> Would you mind to list a few mathematical subjects that help me to
> understand OCamls syntax?
I suppose one is lambda calculus. Function application is
left-associative in ML. That is, if $ is an operator such as a $ b
means "a applied to b", then it is more natural to interpret a $ b $ c
as (a $ b) $ c[1]. The apply "operator" is simply not written in
OCaml, so we write just a b c, and it means (a b) c.
This is due to the fact that a N parameter function is just a
single-parameter function that return a new "curried" function that
gets N-1 parameters - just like lambda calculus. So one could write
let f = a b in f c to make this explicit as well. (This gets a bit
more complicated with optional parameters)
In fact, you want some mathematical background on functional
programming aesthetics (and whatnot),
http://en.wikipedia.org/wiki/Lambda_calculus may be a good
introduction.
[1] Pervasives should define it. In fact, even though ** is
right-associative, it looks like any user-defined operator is
left-associative by default. So it works like Haskell:
# let ($) a b = a b;;
val ( $ ) : ('a -> 'b) -> 'a -> 'b = <fun>
# fun x y z -> x $ y $ z;;
- : ('a -> 'b -> 'c) -> 'a -> 'b -> 'c = <fun>
# let q = fun x y z -> x $ y $ z;;
val q : ('a -> 'b -> 'c) -> 'a -> 'b -> 'c = <fun>
# let q' = fun x y z -> (x $ y) $ z;;
val q' : ('a -> 'b -> 'c) -> 'a -> 'b -> 'c = <fun>
# let q'' = fun x y z -> x $ (y $ z);;
val q'' : ('a -> 'b) -> ('c -> 'a) -> 'c -> 'b = <fun>
# let q''' = fun x y z -> x $ y z;;
val q''' : ('a -> 'b) -> ('c -> 'a) -> 'c -> 'b = <fun>
--
Elias Gabriel Amaral da Silva <tolkiendili@gmail.com>
next prev parent reply other threads:[~2010-09-24 0:15 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-23 14:56 ben kuin
2010-09-23 15:21 ` [Caml-list] " David MENTRE
2010-09-23 19:50 ` ben kuin
2010-09-24 0:15 ` Elias Gabriel Amaral da Silva [this message]
2010-09-24 7:35 ` David House
2010-09-27 11:43 ` Elias Gabriel Amaral da Silva
2010-09-24 7:48 ` David MENTRE
2010-09-23 15:25 ` bluestorm
2010-09-23 16:23 ` Jake Donham
2010-09-23 18:49 ` ben kuin
2010-09-23 18:54 ` Jake Donham
2010-09-23 19:06 ` Yoann Padioleau
2010-09-23 16:28 ` Michael Ekstrand
2010-09-23 16:35 ` Sylvain Le Gall
[not found] ` <1285259219.1820.15.camel@knine>
2010-09-23 18:43 ` [Caml-list] " ben kuin
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='AANLkTi=7TRCwxgRSPTOCN-1E0-KsWHzquLAoDhVaWAcb@mail.gmail.com' \
--to=tolkiendili@gmail.com \
--cc=benkuin@gmail.com \
--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;
as well as URLs for NNTP newsgroup(s).