fsharp: step 4: Added list and comparison functions.
[jackhill/mal.git] / fsharp / types.fs
CommitLineData
ed3a12f5 1module Types
3b82891f 2
8f1ee487
PS
3 exception ReaderError of string
4 exception EvalError of string
5
6 type
7 Node =
327bd967 8 | Nil
3b82891f
PS
9 | List of Node list
10 | Vector of Node array
6dcc04db 11 | Map of Collections.Map<Node, Node>
ed3a12f5 12 | Symbol of string
327bd967 13 | Keyword of string
ed3a12f5 14 | Number of int64
327bd967
PS
15 | String of string
16 | Bool of bool
8f1ee487
PS
17 | Func of F
18 and
a836d8f3 19 // Compare only on Tag since functions are not IComparable
8f1ee487 20 [<CustomEquality; CustomComparison>]
a836d8f3 21 F = { Tag : int; F : Node list -> Node }
8f1ee487
PS
22
23 override x.Equals(yobj) =
24 match yobj with
a836d8f3 25 | :? F as y -> x.Tag = y.Tag
8f1ee487
PS
26 | _ -> false
27
a836d8f3 28 override x.GetHashCode() = hash x.Tag
8f1ee487
PS
29
30 interface System.IComparable with
31 member x.CompareTo yobj =
32 match yobj with
a836d8f3 33 | :? F as y -> compare x.Tag y.Tag
8f1ee487 34 | _ -> invalidArg "yobj" "Cannot compare values of different types."
a836d8f3
PS
35
36 let TRUE = Bool(true)
37 let SomeTRUE = Some(TRUE)
38 let FALSE = Bool(false)
39 let SomeFALSE = Some(FALSE)
40 let NIL = Nil
41 let SomeNIL = Some(NIL)
42 let ZERO = Number(0L)