From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 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 24E4BBBB7 for ; Tue, 24 Jun 2008 17:43:56 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApsEALOyYEjAXQIn/2dsb2JhbACSLKBI X-IronPort-AV: E=Sophos;i="4.27,697,1204498800"; d="scan'208";a="14483056" Received: from concorde.inria.fr ([192.93.2.39]) by mail3-smtp-sop.national.inria.fr with ESMTP; 24 Jun 2008 17:43:55 +0200 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id m5OFhsoH022275 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Tue, 24 Jun 2008 17:43:55 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvAAAGuyYEjRVYTyeGdsb2JhbACSLEMBDAMEBgcRA59W X-IronPort-AV: E=Sophos;i="4.27,697,1204498800"; d="scan'208";a="26659247" Received: from an-out-0708.google.com ([209.85.132.242]) by mail4-smtp-sop.national.inria.fr with ESMTP; 24 Jun 2008 17:43:54 +0200 Received: by an-out-0708.google.com with SMTP id d33so684349and.97 for ; Tue, 24 Jun 2008 08:43:53 -0700 (PDT) Received: by 10.100.190.14 with SMTP id n14mr15882914anf.50.1214322232400; Tue, 24 Jun 2008 08:43:52 -0700 (PDT) Received: by 10.100.153.10 with HTTP; Tue, 24 Jun 2008 08:43:52 -0700 (PDT) Message-ID: <3a360f590806240843o3c13ba0dpf5553f49e2355464@mail.gmail.com> Date: Tue, 24 Jun 2008 11:43:52 -0400 From: "Hezekiah M. Carty" Sender: hcarty@mulethief.com To: "Richard Jones" Subject: Re: [Caml-list] Custom lexer in Camlp4 Cc: "Jeremy Yallop" , caml-list@inria.fr In-Reply-To: <20080624151626.GA8424@annexia.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <4860F097.1000701@ed.ac.uk> <1214317779-sup-8964@port-ext16.ensta.fr> <486104FF.1080201@ed.ac.uk> <20080624151626.GA8424@annexia.org> X-Google-Sender-Auth: 51f578b7db706ffc X-Miltered: at concorde with ID 4861163A.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; lexer:01 camlp:01 0100,:01 camlp:01 expr:01 expr:01 syntax:01 wiki:01 ocaml:01 foo:01 foo:01 toying:01 ocaml:01 toplevel:01 1.0:98 On Tue, Jun 24, 2008 at 11:16 AM, Richard Jones wrote: > On Tue, Jun 24, 2008 at 03:30:23PM +0100, Jeremy Yallop wrote: > On a related note I had a crazy brainwave that we could use camlp4 to > use 'ordinary' operators in an overloaded context. Something like: > > INT64 (2L * n / 3L) > > The INT64(expr) macro would inspect the AST of expr and change + -> > Int64.add etc. Of course one can do this using the pa_openin macro > and a module which overrides (+) etc, but maybe this is better? I was > going to try modifying parts of virt-df to use this syntax to see if > it would be beneficial. I toyed around with a simple extension to the pa_float example on the camlp4 wiki. The modified version is here: http://0ok.org/code/ocaml/pa_float.ml With this, Float.(1 + 2) becomes (1.0 +. 2.0). However, if you used Foo.(a + b), the result would be (Foo.add a b). In the Int64 case, Int64.(1L + 2L) becomes (Int64.add 1L 2L). Same for (-) -> .sub, ( * ) -> .mul, and (/) -> .div. This is the result of some chatting on IRC and toying around with the pa_float example, so I don't know how write or wrong this implementation is. Another approach I tried after further IRC discussion (thanks to bluestorm and David Teller!) is a twist on pa_openin: http://0ok.org/code/ocaml/pa_context.ml In this case, Foo.(1 + 2) would use the operator Foo.(+) rather than a pre-defined transform of (+) -> Foo.add. This might work well if Num-like ( +/ ) operators were added to modules, since it would allow something along the lines of: Int64.(1L +/ some_int64_value +/ of_int 2 -/ of_float some_float_value) to work properly. (+/) may not be very pretty, but it doesn't conflict with (+) or (+.). David Teller may be doing something like this with the Batteries project. I think Zheng Li released an extension similar to pa_context, but I am not sure how similar or different it is in function. Sadly camlp4 3.10+ does not play well with the toplevel, so these are difficult to work with interactively. I do use pa_context in several places though, and it seems to work well. Hez -- Hezekiah M. Carty Graduate Research Assistant University of Maryland Department of Atmospheric and Oceanic Science