3 type 'a with_meta
= { value : 'a
; meta
: t
}
5 | List
of t list with_meta
6 | Vector
of t list with_meta
7 | Map
of t
MalMap.t with_meta
9 | Symbol
of string with_meta
14 | Fn
of (t list
-> t
) with_meta
21 val compare
: t
-> t
-> int
25 let compare = Pervasives.compare
29 : Map.S
with type key
= MalValue.t
32 exception MalExn
of Types.t
34 let to_bool x
= match x
with
35 | Types.Nil
| Types.Bool
false -> false
38 type mal_type
= MalValue.t
40 let list x
= Types.List
{ Types.value = x
; meta
= Types.Nil
}
41 let map x
= Types.Map
{ Types.value = x
; meta
= Types.Nil
}
42 let vector x
= Types.Vector
{ Types.value = x
; meta
= Types.Nil
}
43 let symbol x
= Types.Symbol
{ Types.value = x
; meta
= Types.Nil
}
44 let fn f
= Types.Fn
{ Types.value = f
; meta
= Types.Nil
}
46 let rec list_into_map target source
=
48 | k
:: v
:: more
-> list_into_map (MalMap.add k v target
) more
50 | _
:: [] -> raise
(Invalid_argument
"Literal maps must contain an even number of forms")
52 let rec mal_list_equal a b
=
53 List.length a
= List.length b
&& List.for_all2 mal_equal a b
55 and mal_hash_equal a b
=
56 if MalMap.cardinal a
= MalMap.cardinal b
58 let identical_to_b k v
= MalMap.mem k b
&& mal_equal v
(MalMap.find k b
) in
59 MalMap.for_all
identical_to_b a
64 | (Types.List a
, Types.List b
)
65 | (Types.List a
, Types.Vector b
)
66 | (Types.Vector a
, Types.List b
)
67 | (Types.Vector a
, Types.Vector b
) -> mal_list_equal a
.Types.value b
.Types.value
68 | (Types.Map a
, Types.Map b
) -> mal_hash_equal a
.Types.value b
.Types.value