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 F315FBC57 for ; Fri, 25 Jun 2010 10:18:07 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArQBABcDJEzRVdY2mGdsb2JhbACTEIwpCBUBAQEBAQgJDAcRIrARggmFZC6IUwEBAwWFHASPCQ X-IronPort-AV: E=Sophos;i="4.53,480,1272837600"; d="scan'208";a="62107332" Received: from mail-bw0-f54.google.com ([209.85.214.54]) by mail1-smtp-roc.national.inria.fr with ESMTP; 25 Jun 2010 10:18:07 +0200 Received: by bwz17 with SMTP id 17so1196061bwz.27 for ; Fri, 25 Jun 2010 01:18:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:sender:received :in-reply-to:references:from:date:x-google-sender-auth:message-id :subject:to:cc:content-type; bh=vdoNvdbAOhI24sExTwViEcQcJMveNJzzIU8JssmphJA=; b=r5GqsLd8MxydPzxkEKl4veRofU8NxppbzQ9zUby77fKEAuBpNEDAlLATyykUIierzl KWZDbM/q6TiVFT+/GTimp1jkP5/siM+EgVyRVWGVwRKCI0fYabRgvBorbn8jzw5gge5V RzclGwtjZOGSUmaFLXIFM/e99HImu0+NbIVCw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type; b=jKakDv480+ih8+NDnBFzUhmFFRmwXle49wcYX9GzCnRO2Imm3s7EKeGYPpeH8XEOZl BCEmUS7XNxBwrdiJaX3GymmJ6wLeb91FWQ+hT74Oe/CpVahd8gzZqEhItUESAAvEytda ixX2I1WQ7Cc3q7qTyUVzvHgfCA72jVEqLM8dE= Received: by 10.204.73.193 with SMTP id r1mr233369bkj.111.1277453886311; Fri, 25 Jun 2010 01:18:06 -0700 (PDT) MIME-Version: 1.0 Sender: gabriel.scherer@gmail.com Received: by 10.204.68.148 with HTTP; Fri, 25 Jun 2010 01:17:46 -0700 (PDT) In-Reply-To: <20100625082404.19864c8w6r8962kk@webmail.imag.fr> References: <4C232778.2020605@imag.fr> <4C2399B0.4060503@ens-lyon.org> <20100624205906.48451eor602oaf3u@webmail.imag.fr> <20100624224944.91886zxkgzxq78iw@webmail.imag.fr> <20100625000544.142418fa5cp6ye9k@webmail.imag.fr> <20100625082404.19864c8w6r8962kk@webmail.imag.fr> From: bluestorm Date: Fri, 25 Jun 2010 10:17:46 +0200 X-Google-Sender-Auth: 1n0VqoszvUcgdqSNiCxNChTN-Qc Message-ID: Subject: Re: [Caml-list] OCaml 3.12.0+beta1 To: Florent Ouchet Cc: "Hezekiah M. Carty" , caml users Content-Type: multipart/alternative; boundary=0016e6dd8f611c61490489d6699b X-Spam: no; 0.00; ocaml:01 camlp:01 camlp:01 ocaml-:01 byterun:01 ocamlrun:01 otherlibs:01 byte:01 byterun:01 ocamlrun:01 ocamlc:01 stdlib:01 otherlibs:01 byte:01 cmo:01 --0016e6dd8f611c61490489d6699b Content-Type: text/plain; charset=ISO-8859-1 Here is a small Camlp4 filter removing exhaustive patterns. It obviously depends on 3.12. open Camlp4.PreCast;; let filter = function | <:patt@_loc< { $p$ } >> -> let rec clean = function | <:patt< _ ; $p$ >> | <:patt< $p$; _ >> -> clean p | <:patt@_loc< $p1$; $p2$ >> -> <:patt< $clean p1$; $clean p2$ >> | p -> p in <:patt< { $clean p$ } >> | t -> t ;; AstFilters.register_str_item_filter (Ast.map_patt filter)#str_item;; (* #step I used to compile and test the code from a freshly compiiled (but not installed) ocaml-3.12 beta : #I build using fastworld.sh (see INSTALL) then `cd _build` ../byterun/ocamlrun -I otherlibs/unix/ camlp4/camlp4orf.byte /tmp/ exhaustive_record_stripper.ml -o /tmp/stripper.ml ../byterun/ocamlrun ./ocamlc -I stdlib -I camlp4 /tmp/stripper.ml -c ../byterun/ocamlrun -I otherlibs/unix/ camlp4/camlp4o.byte /tmp/stripper.cmo -str 'fun {a; b; _} -> c' #output : fun { a = a; b = b } -> c *) Notes : - that the OCaml printer expand sugared { a; b } patters into { a = a; b = b } is necessary for printing backward-compatible code; I'm not sure it's a good idea to rely on this. - as with every camlp4 filters, the code is parsed then pretty-printed; do not expect indentation to stay as is. Comment placement is also going to do weird things (know and nearly-unfixable camlp4 defect) : ocamldoc may not work properly on the output code. --0016e6dd8f611c61490489d6699b Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Here is a small Camlp4 filter removing exhaustive patterns. It obviously de= pends on 3.12.

=A0=A0open Camlp4.PreCast;;
=A0=A0
=A0=A0let filter =3D
=A0=A0 =A0function
<= div>=A0=A0 =A0| <:patt@_loc< { $p$ } >> ->
=A0=A0 =A0 =A0let rec clean =3D function
=A0=A0 =A0 =A0 =A0|= <:patt< _ ; $p$ >> | <:patt< $p$; _ >> -> clean= p
=A0=A0 =A0 =A0 =A0| <:patt@_loc< $p1$; $p2$ >> -&g= t; <:patt< $clean p1$; $clean p2$ >>
=A0=A0 =A0 =A0 =A0| p -> p in
=A0=A0 =A0 =A0<:patt<= { $clean p$ } >>
=A0=A0 =A0| t -> t
=A0=A0;;<= /div>
=A0=A0
=A0=A0AstFilters.register_str_item_filter (Ast.m= ap_patt filter)#str_item;;
=A0=A0
=A0=A0
=A0=A0(*
=A0=A0#step I use= d to compile and test the code from a freshly compiiled (but not installed)= ocaml-3.12 beta :
=A0=A0#I build using fastworld.sh (see INSTALL= ) then `cd _build`
=A0=A0../byterun/ocamlrun -I otherlibs/unix/ camlp4/camlp4orf.byte /tm= p/exhaustive_record_stripp= er.ml -o /tmp/stripper.ml
= =A0=A0../byterun/ocamlrun ./ocamlc -I stdlib -I camlp4 /tmp/stripper.ml -c
=A0=A0 ../byterun/ocamlrun -I otherlibs/unix/ camlp4/camlp4o.byte /tmp= /stripper.cmo -str 'fun {a; b; _} -> c'
=A0=A0#output = : fun { a =3D a; b =3D b } -> c
=A0=A0*)

<= /div>

Notes :
- that the OCaml printer expand sugared { a; b= } patters into { a =3D a; b =3D b } is necessary for printing backward-com= patible code; I'm not sure it's a good idea to rely on this.
- as with every camlp4 filters, the code is parsed then pretty-printed; do = not expect indentation to stay as is. Comment placement is also going to do= weird things (know and nearly-unfixable camlp4 defect) : ocamldoc may not = work properly on the output code.
--0016e6dd8f611c61490489d6699b--