1
0
Fork 0
This repository has been archived on 2024-05-03. You can view files and clone it, but cannot push or open issues or pull requests.
unification-pfa/lib/term.ml

50 lines
1 KiB
OCaml
Raw Normal View History

type binop =
| Plus
| Minus
| Times
| Div
[@@deriving eq, ord, show]
type projection =
| First
| Second
[@@deriving eq, ord, show]
type t =
| Var of Identifier.t
| IntConst of int
| Binop of t * binop * t
| Pair of t * t
| Proj of projection * t
| Fun of Identifier.t * t
| App of t * t
[@@deriving eq, ord, show]
2024-04-13 20:15:39 +02:00
let rec string_of_term = function
| Var v -> "Var '" ^ v ^ "'"
2024-04-27 12:33:39 +02:00
| IntConst n -> string_of_int n
2024-04-13 20:15:39 +02:00
| Binop (a, b, c) ->
"Binop ("
^ string_of_term a
2024-04-27 12:33:39 +02:00
^ " "
2024-04-13 20:15:39 +02:00
^ (match b with
| Plus -> "+"
| Minus -> "-"
| Times -> "*"
| Div -> "/")
2024-04-27 12:33:39 +02:00
^ " "
2024-04-13 20:15:39 +02:00
^ string_of_term c
^ ")"
| Pair (a, b) -> "Pair (" ^ string_of_term a ^ ", " ^ string_of_term b ^ ")"
| Proj (a, b) ->
"Proj ("
^ (match a with
| First -> "fst"
| Second -> "snd")
^ ", "
^ string_of_term b
^ ")"
| Fun (a, b) -> "Fun ('" ^ a ^ "', " ^ string_of_term b ^ ")"
| App (a, b) -> "App (" ^ string_of_term a ^ ", " ^ string_of_term b ^ ")"
;;