summaryrefslogtreecommitdiffstats
path: root/syntax.sml
diff options
context:
space:
mode:
Diffstat (limited to 'syntax.sml')
-rw-r--r--syntax.sml9
1 files changed, 9 insertions, 0 deletions
diff --git a/syntax.sml b/syntax.sml
index fbb4dfd..767851d 100644
--- a/syntax.sml
+++ b/syntax.sml
@@ -12,6 +12,7 @@ struct
| PVar of string
| PInt of int
| PTuple of pat list
+ | PCon of string * pat
datatype expr =
EIdent of string list
@@ -31,6 +32,7 @@ struct
and dec =
DVal of pat * expr
| DValRec of pat * expr
+ | DDatatype of string * (string * etype option) list
(* Lambda language *)
type var = int
@@ -101,6 +103,11 @@ struct
fun quote (s : string) : string = "\"" ^ String.toString s ^ "\""
+ fun optionToString (show : 'a -> string) (x : 'a option) =
+ case x of
+ NONE => "NONE"
+ | SOME x => "SOME " ^ show x
+
fun etypeToString (x : etype) : string =
case x of
Tyvar s => "Tyvar " ^ quote s
@@ -114,6 +121,7 @@ struct
| PVar v => "PVar " ^ quote v
| PInt i => "PInt " ^ Int.toString i
| PTuple pats => "PTuple " ^ listToString patToString pats
+ | PCon (con, v) => "PCon " ^ "(" ^ quote con ^ ", " ^ patToString v ^ ")"
fun exprToStringI (indent : string) (x : expr) : string =
let val self = exprToStringI indent
@@ -137,6 +145,7 @@ struct
case x of
DVal (p, e) => "DVal (" ^ patToString p ^ ", " ^ exprToStringI indent e ^ ")"
| DValRec (p, e) => "DValRec (" ^ patToString p ^ ", " ^ exprToStringI indent e ^ ")"
+ | DDatatype (name, arms) => "DDatatype (" ^ quote name ^ ", " ^ listToString (fn (con, v) => "(" ^ quote con ^ ", " ^ optionToString etypeToString v ^ ")") arms ^ ")"
val exprToString : expr -> string = exprToStringI ""