From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id C4282BC57 for ; Fri, 24 Sep 2010 02:15:01 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjkBAOuJm0xKfVI0kGdsb2JhbACiLggVAQEBAQkJDAcRAx+sMok9ghSGZy6IVQEBAwWFPQSKOIVg X-IronPort-AV: E=Sophos;i="4.57,226,1283724000"; d="scan'208";a="73015906" Received: from mail-ww0-f52.google.com ([74.125.82.52]) by mail1-smtp-roc.national.inria.fr with ESMTP; 24 Sep 2010 02:15:01 +0200 Received: by wwi17 with SMTP id 17so493306wwi.9 for ; Thu, 23 Sep 2010 17:15:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type; bh=PBk5pZvZpwmp8W+TRvMmlpmkRo5UDT59Z05kc3riObw=; b=F/LZWHgLOIzetPWhiyV+8cj+970uCgXidW6VcX7PgSXkiDPD6tWT5r6GK6xQ+j2AQc 89GmHPk+JkyjG4YlWuz5aiyJbJHOcLuUHzIISggSkptIxSAQwzsntZl2RQT4SUAQvcg9 oDAG4LdKBZ9Y4DVpiyPUpw8zA1Jf5rVrN+TF0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=plhPWClyVOulSBDJzBNT66CeuCkw676vX3ywNvXac9Yg0PyvDm8v9GTEbnOfDP1Mg+ Pm1fivIf5cQe/U+eXJh3mvAhvHwVNqyhsa/tZy16d2LmqIoCXlgLGdn6pf7ndoDibmWi Ss3LwBbRxmm7cALNi/2VZw2EA31t6gUpZcUrU= MIME-Version: 1.0 Received: by 10.216.231.26 with SMTP id k26mr2149844weq.3.1285287300642; Thu, 23 Sep 2010 17:15:00 -0700 (PDT) Received: by 10.216.131.37 with HTTP; Thu, 23 Sep 2010 17:15:00 -0700 (PDT) In-Reply-To: References: Date: Thu, 23 Sep 2010 21:15:00 -0300 Message-ID: Subject: Re: [Caml-list] what do I need to know to understand camlp4 From: Elias Gabriel Amaral da Silva To: ben kuin Cc: caml-list@inria.fr Content-Type: text/plain; charset=ISO-8859-1 X-Spam: no; 0.00; camlp:01 syntax:01 notation:01 syntax:01 lambda:01 ocaml:01 curried:01 lambda:01 wikipedia:01 wiki:01 pervasives:01 haskell:01 val:01 val:01 silva:98 2010/9/23 ben kuin : >> [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 x y z -> x $ y $ z;; - : ('a -> 'b -> 'c) -> 'a -> 'b -> 'c = # let q = fun x y z -> x $ y $ z;; val q : ('a -> 'b -> 'c) -> 'a -> 'b -> 'c = # let q' = fun x y z -> (x $ y) $ z;; val q' : ('a -> 'b -> 'c) -> 'a -> 'b -> 'c = # let q'' = fun x y z -> x $ (y $ z);; val q'' : ('a -> 'b) -> ('c -> 'a) -> 'c -> 'b = # let q''' = fun x y z -> x $ y z;; val q''' : ('a -> 'b) -> ('c -> 'a) -> 'c -> 'b = -- Elias Gabriel Amaral da Silva