blob: 9f74deea6cb0548d17b49bc3a81d94dcb95eddd3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
(****************************************************************************)
(* *)
(* OCaml *)
(* *)
(* INRIA Rocquencourt *)
(* *)
(* Copyright 2008 Institut National de Recherche en Informatique et *)
(* en Automatique. All rights reserved. This file is distributed under *)
(* the terms of the GNU Library General Public License, with the special *)
(* exception on linking described in LICENSE at the top of the OCaml *)
(* source tree. *)
(* *)
(****************************************************************************)
open Fancy_lambda_quot.LambdaSyntax;;
let _loc = Camlp4.PreCast.Loc.ghost;;
let rec propagate = function
| << $f$ $x$ $y$ >> ->
begin match propagate f, propagate x, propagate y with
| f, << $int:i$ >>, << $int:j$ >> ->
begin match f with
| << plus >> -> << $int:i + j$ >>
| << minus >> -> << $int:i - j$ >>
| << times >> -> << $int:i * j$ >>
| << div >> -> << $int:i / j$ >>
| _ -> << $f$ $int:i$ $int:j$ >>
end
| f, x, y -> << $f$ $x$ $y$ >>
end
| << $f$ $x$ >> -> << $propagate f$ $propagate x$ >>
| << fun $x$ -> $e$ >> -> << fun $x$ -> $propagate e$ >> (* here x should not be a primitive like plus *)
| << $var:_$ >> | << $int:_$ >> as e -> e
;;
let ex1 = propagate << f (fun x -> g (plus 3 (times 4 42)) (minus 1 (x 3))) >>
;;
|