Browse thread
OCaml 3.12.0+beta1
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | bluestorm <bluestorm.dylc@g...> |
| Subject: | Re: [Caml-list] OCaml 3.12.0+beta1 |
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.