diff options
| author | Rose Hogenson <rosehogenson@posteo.net> | 2025-05-18 08:17:20 -0700 |
|---|---|---|
| committer | Rose Hogenson <rosehogenson@posteo.net> | 2025-06-13 19:14:58 -0700 |
| commit | 8b3a9b8f0d80e7dd789f363deb6bb36189a31f01 (patch) | |
| tree | 414ac8c234ded42f1bf4d8da7a96a4c7078db95f /Syntax.sml | |
| parent | Add .envrc (diff) | |
| download | sml-8b3a9b8f0d80e7dd789f363deb6bb36189a31f01.tar.zst | |
Add a typechecker
Diffstat (limited to 'Syntax.sml')
| -rw-r--r-- | Syntax.sml | 56 |
1 files changed, 53 insertions, 3 deletions
@@ -15,7 +15,8 @@ struct | PCon of string list * pat datatype expr = - EIdent of string list + EIdent of string + | EDot of structExpr * string | EBuiltin of string | EInt of int | EStr of string @@ -33,14 +34,63 @@ struct DVal of pat * expr | DValRec of pat * expr | DFun of string * (pat list * expr) list - | DDatatype of string * (string * etype option) list + | DDatatype of string list * string * (string * etype option) list | DType of string * etype | DStruct of string * structExpr and structExpr = - SIdent of string list + SIdent of string + | SDot of structExpr * string | SStruct of dec list + datatype ty = + TInt + | TBool + | TString + | TVar of int + | TTuple of ty list + | 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 *) + + datatype typedPat = + TPWild + | TPVar of string + | TPInt of int + | TPTuple of (typedPat * ty) list + | TPCon of string list * (typedPat * ty) + + datatype typedExpr = + TEIdent of string + | TEDot of (typedStructExpr * structType) * string + | TEBuiltin of string + | TEInt of int + | TEStr of string + | TETuple of (typedExpr * ty) list + | TEList of (typedExpr * ty) list + | TEApp of (typedExpr * ty) * (typedExpr * ty) + | TEAndAlso of (typedExpr * ty) * (typedExpr * ty) + | TEOrElse of (typedExpr * ty) * (typedExpr * ty) + | TELet of typedDec list * (typedExpr * ty) + | TELambda of (typedPat * ty) * (typedExpr * ty) + | TECase of (typedExpr * ty) * ((typedPat * ty) * (typedExpr * ty)) list + + 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 + (* Lambda language *) type var = int |
