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 mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 418EABC57 for ; Fri, 24 Sep 2010 09:35:48 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Aj4CAEbxm0xKfVK2kGdsb2JhbACiMAgVAQECCQkMBxEDH6lUiT2CFIZJLohVAQEDBYU9BIo4hWA X-IronPort-AV: E=Sophos;i="4.57,228,1283724000"; d="scan'208";a="59086887" Received: from mail-wy0-f182.google.com ([74.125.82.182]) by mail3-smtp-sop.national.inria.fr with ESMTP; 24 Sep 2010 09:35:47 +0200 Received: by wyb33 with SMTP id 33so3631451wyb.27 for ; Fri, 24 Sep 2010 00:35:47 -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=xxJDUvfSXnlQuIk2tjo1oAqAlJJu/Lm2BQ1unCnM3BE=; b=iM3cSUxXKR3Yp4nqDVaj5OpFUZ1uBuxHBLtNfow3wkGscc2UyApzEF5xuaYEi/3QGG taumXvTWVBANSCWnfKfrVTTQw94AUHONkNAht6wefT7IkA00oPRcXUXEkpam8BkEyHW8 yKOTf3FE6x9CUODC/4AR/bVr1GH1em19jQ+yo= 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=CWqisAVhKnSnILnf7ArDkSHuIGAiXUId14VKkbIvE/QxAel32I20bDYYFKJ2c7GF3K OBMGte7zjP3dERtDTkq1V549fV2Eqv3HLHtnRRQk+ViiAzzACotLYAYDSU0UC6O8oETP MjvaNeTSfqpLyhy2o1HQhxscVcIrANKn2/GdE= MIME-Version: 1.0 Received: by 10.227.127.130 with SMTP id g2mr2591660wbs.67.1285313747225; Fri, 24 Sep 2010 00:35:47 -0700 (PDT) Received: by 10.227.141.205 with HTTP; Fri, 24 Sep 2010 00:35:46 -0700 (PDT) In-Reply-To: References: Date: Fri, 24 Sep 2010 08:35:46 +0100 Message-ID: Subject: Re: [Caml-list] what do I need to know to understand camlp4 From: David House To: Elias Gabriel Amaral da Silva Cc: ben kuin , caml-list@inria.fr Content-Type: text/plain; charset=ISO-8859-1 X-Spam: no; 0.00; camlp:01 pervasives:01 haskell:01 val:01 val:01 haskell:01 wiki:01 pervasives:01 ocaml:01 infix:01 silva:98 wrote:01 precedence:01 precedence:01 caml-list:01 On 24 September 2010 01:15, Elias Gabriel Amaral da Silva wrote: > [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 = Incidentally, ($) in Haskell is right-associative; however the consensus in the Haskell community (in my experience) is that this is a mistake. If it were left-associative, you would lose the ability to say f $ g $ x, but this can be written f . g $ x anyway (dot is function composition (a -> b) -> (b -> c) -> a -> c, and does right-associate), but many things would require fewer parentheses, e.g. f (g x) (h y) can be written f $ g x $ h y. In fact, the strict function application operator ($!) *is* left-associative. See http://hackage.haskell.org/trac/haskell-prime/wiki/ChangeDollarAssociativity for more information. Also, you say "Pervasives should define it" -- the important thing about dollar in Haskell is that it has very low precedence, hence its ability to save parentheses. I didn't think OCaml allowed us to specify the operator precedence of the infix operators we define.