summaryrefslogtreecommitdiffstats
path: root/Syntax.sml
diff options
context:
space:
mode:
Diffstat (limited to 'Syntax.sml')
-rw-r--r--Syntax.sml51
1 files changed, 31 insertions, 20 deletions
diff --git a/Syntax.sml b/Syntax.sml
index c9e4323..0eccd36 100644
--- a/Syntax.sml
+++ b/Syntax.sml
@@ -14,9 +14,25 @@ struct
| PTuple of pat list
| PCon of string list * pat
+ datatype identType =
+ ITVar
+ | ITStruct
+ | ITFunctor
+ | ITSignature
+
+ fun identTypeOrder ITVar = 0
+ | identTypeOrder ITStruct = 1
+ | identTypeOrder ITFunctor = 2
+ | identTypeOrder ITSignature = 3
+
+ fun compareIdentifiers ((t1, n1) : identType * string, (t2, n2) : identType * string) : order =
+ case Int.compare (identTypeOrder t1, identTypeOrder t2) of
+ EQUAL => String.compare (n1, n2)
+ | ord => ord
+
datatype expr =
- EIdent of string
- | EDot of structExpr * string
+ EIdent of identType * string
+ | EDot of expr * (identType * string)
| EBuiltin of string
| EInt of int
| EStr of string
@@ -29,6 +45,8 @@ struct
| ELet of dec list * expr
| ELambda of pat * expr
| ECase of expr * (pat * expr) list
+ | EStruct of dec list
+ | EFunctorApp of expr * expr
and dec =
DVal of pat * expr
@@ -36,13 +54,10 @@ struct
| DFun of string * (pat list * expr) list
| DDatatype of string list * string * (string * etype option) list
| DType of string * etype
- | DStruct of string * string option * structExpr
+ | DStruct of string * string option * expr
| DSig of string * (string * etype) list
-
- and structExpr =
- SIdent of string
- | SDot of structExpr * string
- | SStruct of dec list
+ (* Functor? I hardly know 'er! *)
+ | DFunctor of string * string * string * expr
datatype ty =
TInt
@@ -53,10 +68,8 @@ struct
| TFun of ty * ty
| TList of ty
| TDatatype of string list
-
- datatype structType =
- TStruct of (string * structType) list * (string * ty) list
-(*| TFunctor of structType * structType *)
+ | TStruct of ((identType * string) * ty) list
+ | TFunctor of ty * ty
datatype typedPat =
TPWild
@@ -66,8 +79,8 @@ struct
| TPCon of string list * (typedPat * ty)
datatype typedExpr =
- TEIdent of string
- | TEDot of (typedStructExpr * structType) * string
+ TEIdent of identType * string
+ | TEDot of (typedExpr * ty) * (identType * string)
| TEBuiltin of string
| TEInt of int
| TEStr of string
@@ -79,18 +92,16 @@ struct
| TELet of typedDec list * (typedExpr * ty)
| TELambda of (typedPat * ty) * (typedExpr * ty)
| TECase of (typedExpr * ty) * ((typedPat * ty) * (typedExpr * ty)) list
+ | TEStruct of typedDec list
+ | TEFunctorApp of (typedExpr * ty) * (typedExpr * ty)
and typedDec =
TDVal of (typedPat * ty) * (typedExpr * ty)
| TDValRec of (typedPat * ty) * (typedExpr * ty)
| TDFun of string * ((typedPat * ty) list * (typedExpr * ty)) list
| TDDatatype of string * (string * ty option) list
- | TDStruct of string * (typedStructExpr * structType)
-
- and typedStructExpr =
- TSIdent of string
- | TSDot of (typedStructExpr * structType) * string
- | TSStruct of typedDec list
+ | TDStruct of string * (typedExpr * ty)
+ | TDFunctor of string * string * ty * (typedExpr * ty)
(* Lambda language *)
type var = int