├── main ├── wrap-alice.sml ├── wrap-mlkit.sml ├── wrap-mlton.sml ├── wrap-mosml.sml ├── wrap-generic.sml ├── wrap-hamlet.sml ├── MAIN-sig.sml ├── wrap-poly.sml ├── wrap-smlnj.sml ├── Makefile.depend.in ├── SML-sig.sml └── wrap-smlsharp.sml ├── sh ├── hamlet-alice.sh ├── hamlet-alice.sh.bat ├── hamlet-smlnj.sh ├── hamlet-smlnj.sh.bat └── make.bat.in ├── test ├── asterisk.sml ├── tyvar-shadowing.sml ├── tyname.sml ├── flexrecord.sml ├── withtype.sml ├── abstype2.sml ├── fun-case.sml ├── semicolon.sml ├── open.sml ├── where2.sml ├── fun-partial.sml ├── generalise.sml ├── typespec.sml ├── abstype.sml ├── overloading.sml ├── undetermined.sml ├── id.sml ├── poly-exception.sml ├── undetermined3.sml ├── scon.sml ├── replication.sml ├── undetermined2.sml ├── functor-poly2.sml ├── sharing.sml ├── valrec.sml ├── where.sml ├── fun-infix.sml ├── redundant.sml ├── functor-poly.sml ├── flexrecord2.sml ├── where-and.sml └── dec-strdec.sml ├── basis ├── LargeInt.sml ├── LargeReal.sml ├── LargeWord.sml ├── Position.sml ├── COMMAND_LINE-sig.sml ├── infix.sml ├── OS.sml ├── CommandLine.sml ├── Word8Vector.sml ├── Word8VectorSlice.sml ├── IO.sml ├── IO-sig.sml ├── TEXT_STREAM_IO-sig.sml ├── BOOL-sig.sml ├── OS_Process.sml ├── exceptions.sml ├── Word8Array.sml ├── BYTE-sig.sml ├── OS_PROCESS-sig.sml ├── OS-sig.sml ├── OS_FileSys.sml ├── types.sml ├── MATH-sig.sml ├── GENERAL-sig.sml ├── OPTION-sig.sml ├── IEEEReal.sml ├── STRING_CVT-sig.sml ├── Text.sml ├── TEXT-sig.sml ├── CharArray.sml ├── General.sml ├── Option.sml ├── Byte.sml ├── Word8ArraySlice.sml ├── IEEE_REAL-sig.sml ├── CharArraySlice.sml ├── LIST_PAIR-sig.sml ├── Math.sml ├── MONO_VECTOR-sig.sml ├── VECTOR-sig.sml ├── OS_FILE_SYS-sig.sml ├── values.sml ├── INTEGER-sig.sml ├── IMPERATIVE_IO-sig.sml ├── StringCvt.sml ├── STREAM_IO-sig.sml ├── LIST-sig.sml ├── MONO_VECTOR_SLICE-sig.sml ├── MONO_ARRAY-sig.sml ├── ARRAY-sig.sml ├── OS_PATH-sig.sml ├── VECTOR_SLICE-sig.sml ├── STRING-sig.sml ├── MONO_ARRAY_SLICE-sig.sml ├── ARRAY_SLICE-sig.sml ├── CHAR-sig.sml └── WORD-sig.sml ├── .gitignore ├── fix ├── TextIO.sml ├── CharVector.sml ├── OS.sml ├── CommandLine-smlsharp.sml ├── Makefile.depend.in ├── Word.sml ├── Large.sml ├── Real-mlkit.sml ├── Real-mosml.sml └── ListPair.sml ├── lib ├── USE-sig.sml ├── Use.sml ├── DYNAMIC_LIBRARY-sig.sml ├── STATIC_LIBRARY-sig.sml ├── Makefile.depend.in └── IdsLibrary.sml ├── syntax ├── PP_MODULE-sig.sml ├── PP_PROGRAM-sig.sml ├── IDSTATUS-sig.sml ├── IdStatus.sml ├── PPProgram.sml ├── SOURCE-sig.sml ├── LAB-sig.sml ├── SCON-sig.sml ├── SyntaxProgramFn.sml ├── ID-sig.sml ├── PP_SYNTAX-sig.sml ├── IdFn.sml ├── SCon.sml ├── TYVAR-sig.sml ├── IdsModule.sml ├── Lab.sml ├── LONGID-sig.sml ├── ANNOTATION-sig.sml ├── PP_CORE-sig.sml ├── Source.sml ├── Annotation.sml └── LongIdFn.sml ├── doc ├── README.txt ├── Makefile ├── announce │ ├── announcement.txt │ ├── announcement1.1.txt │ └── announcement2.0.txt └── INSTALL.txt ├── compile-js ├── PP_JS-sig.sml ├── JS_TRANSLATE_SCON-sig.sml ├── JS_TRANSLATE_PROGRAM-sig.sml ├── COMPILE_JS-sig.sml ├── JS_TRANSLATE_MODULE-sig.sml ├── ID_SET_CORE-sig.sml ├── JS_TRANSLATE_CORE-sig.sml ├── ID_SET_MODULE-sig.sml ├── CompileJS.sml └── JS_TRANSLATE_ID-sig.sml ├── exec ├── PP_BASIS-sig.sml ├── PP_ENV-sig.sml ├── PPBasis.sml ├── BASIS-sig.sml ├── PROGRAM-sig.sml ├── Basis.sml └── Makefile.depend.in ├── README.md ├── eval ├── PP_DYNAMIC_BASIS-sig.sml ├── PP_DYNAMIC_ENV-sig.sml ├── ADDR-sig.sml ├── PP_VAL-sig.sml ├── INITIAL_DYNAMIC_BASIS-sig.sml ├── EVAL_MODULE-sig.sml ├── BASVAL-sig.sml ├── EXNAME-sig.sml ├── Addr.sml ├── DYNAMIC_ENV-sig.sml ├── STATE-sig.sml ├── State.sml ├── InitialDynamicBasis.sml ├── SVAL-sig.sml ├── VAL-sig.sml ├── EVAL_PROGRAM-sig.sml ├── IntBasis.sml ├── DynamicEnv.sml ├── INTBASIS-sig.sml ├── ExName.sml ├── BasVal.sml ├── EVAL_CORE-sig.sml ├── INITIAL_DYNAMIC_ENV-sig.sml ├── EvalProgram.sml ├── INTER-sig.sml ├── PPDynamicBasis.sml ├── SVal.sml ├── DynamicObjectsModule.sml └── DYNAMIC_BASIS-sig.sml ├── parse ├── INITIAL_INFIX_ENV-sig.sml ├── BINDING_ENV-sig.sml ├── PARSE-sig.sml ├── SYNTACTIC_RESTRICTIONS_PROGRAM-sig.sml ├── SYNTACTIC_RESTRICTIONS_MODULE-sig.sml ├── BindingEnv.sml ├── DERIVED_FORMS_PROGRAM-sig.sml ├── InitialInfixEnv.sml ├── BindingObjectsModule.sml ├── SyntacticRestrictionsProgram.sml ├── DerivedFormsProgram.sml ├── INFIX-sig.sml ├── BindingContext.sml ├── BindingObjectsCore.sml ├── BINDING_CONTEXT-sig.sml └── BINDING_BASIS-sig.sml ├── smlnj-lib ├── ord-key-sig.sml ├── ml-yacc-lib.cm ├── lib-base-sig.sml ├── Makefile.depend.in ├── fifo-sig.sml ├── stream.sml ├── lib-base.sml ├── queue.sml ├── LICENSE.txt └── queue-sig.sml ├── elab ├── INITIAL_STATIC_BASIS-sig.sml ├── PP_TYPE-sig.sml ├── SCOPE_TYVARS-sig.sml ├── ELAB_MODULE-sig.sml ├── CLOS-sig.sml ├── PP_STATIC_BASIS-sig.sml ├── InitialStaticBasis.sml ├── FUNSIG-sig.sml ├── ELAB_PROGRAM-sig.sml ├── PP_STATIC_ENV-sig.sml ├── FunSig.sml ├── SIG-sig.sml ├── ELAB_CORE-sig.sml ├── StaticObjectsModule.sml ├── ElabProgram.sml ├── INITIAL_STATIC_ENV-sig.sml ├── TYNAME-sig.sml ├── STATIC_ENV-sig.sml ├── TYPEFCN-sig.sml ├── TYPESCHEME-sig.sml ├── CHECK_PATTERN-sig.sml └── PPStaticBasis.sml ├── infrastructure ├── STAMP-sig.sml ├── FIN_SET-sig.sml ├── Stamp.sml ├── PROP-sig.sml ├── FinSetFn.sml ├── Prop.sml ├── PP_MISC-sig.sml ├── FIN_MAP-sig.sml ├── ERROR-sig.sml ├── Makefile.depend.in ├── FinMapFn.sml ├── PPMisc.sml └── PRETTY_PRINT-sig.sml ├── valid ├── SCOPE_TYVARS-sig.sml ├── VALID_MODULE-sig.sml └── VALID_CORE-sig.sml └── compile-f └── F_STATIC-sig.sml /main/wrap-alice.sml: -------------------------------------------------------------------------------- 1 | do Main.main() 2 | -------------------------------------------------------------------------------- /main/wrap-mlkit.sml: -------------------------------------------------------------------------------- 1 | val _ = Main.main() 2 | -------------------------------------------------------------------------------- /main/wrap-mlton.sml: -------------------------------------------------------------------------------- 1 | val _ = Main.main() 2 | -------------------------------------------------------------------------------- /main/wrap-mosml.sml: -------------------------------------------------------------------------------- 1 | val _ = Main.main() 2 | -------------------------------------------------------------------------------- /sh/hamlet-alice.sh: -------------------------------------------------------------------------------- 1 | alicerun hamlet $@ 2 | -------------------------------------------------------------------------------- /main/wrap-generic.sml: -------------------------------------------------------------------------------- 1 | val _ = Main.main() 2 | -------------------------------------------------------------------------------- /main/wrap-hamlet.sml: -------------------------------------------------------------------------------- 1 | val _ = Sml.execSession(); 2 | -------------------------------------------------------------------------------- /sh/hamlet-alice.sh.bat: -------------------------------------------------------------------------------- 1 | @alicerun hamlet %1 %2 %3 %4 %5 %6 %7 %8 %9 2 | -------------------------------------------------------------------------------- /sh/hamlet-smlnj.sh: -------------------------------------------------------------------------------- 1 | sml @SMLload=`dirname $0`/hamlet-image @SMLcmdname=$0 "$@" 2 | -------------------------------------------------------------------------------- /sh/hamlet-smlnj.sh.bat: -------------------------------------------------------------------------------- 1 | @sml "@SMLload=hamlet-image" "@SMLcmdname=%0" %1 %2 %3 %4 %5 %6 %7 %8 %9 2 | -------------------------------------------------------------------------------- /test/asterisk.sml: -------------------------------------------------------------------------------- 1 | (* asterisk.sml *) 2 | 3 | (* Checks parsing of "* )". *) 4 | 5 | val op* = (op*); 6 | -------------------------------------------------------------------------------- /basis/LargeInt.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library 5 | *) 6 | 7 | structure LargeInt = Int; 8 | -------------------------------------------------------------------------------- /basis/LargeReal.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library 5 | *) 6 | 7 | structure LargeReal = Real; 8 | -------------------------------------------------------------------------------- /basis/LargeWord.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library 5 | *) 6 | 7 | structure LargeWord = Word; 8 | -------------------------------------------------------------------------------- /test/tyvar-shadowing.sml: -------------------------------------------------------------------------------- 1 | (* tyvar-shadowing.sml *) 2 | 3 | (* Checks that type variables may not be shadowed. *) 4 | 5 | val 'a x = let val 'a y = () in () end; 6 | -------------------------------------------------------------------------------- /test/tyname.sml: -------------------------------------------------------------------------------- 1 | (* tyname.sml *) 2 | 3 | (* Checks scoping of type names (should be rejected!). *) 4 | 5 | let 6 | val r = ref nil 7 | datatype t = C 8 | in 9 | r := [C] 10 | end; 11 | -------------------------------------------------------------------------------- /test/flexrecord.sml: -------------------------------------------------------------------------------- 1 | (* flexrecord.sml *) 2 | 3 | (* Checks type inference for flexible records. *) 4 | 5 | fun f(r as {...}) = 6 | let 7 | fun g() = r 8 | in 9 | [r, {a = 1}] 10 | end; 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.depend 2 | */*.depend 3 | */.DS_Store 4 | */*.zip 5 | */*.gz 6 | hamlet* 7 | *.tmproj 8 | doc/*.aux 9 | doc/*.dvi 10 | doc/*.log 11 | doc/*.out 12 | doc/*.pdf 13 | doc/*.ps 14 | doc/*.toc 15 | *.bat 16 | -------------------------------------------------------------------------------- /test/withtype.sml: -------------------------------------------------------------------------------- 1 | (* withtype.sml *) 2 | 3 | (* Checks scoping rules of withtype *) 4 | 5 | type u = int 6 | 7 | datatype t = T of u * v 8 | withtype u = bool 9 | and v = u 10 | 11 | val x = T(true, 6); 12 | -------------------------------------------------------------------------------- /main/MAIN-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML implementation stand-alone 5 | *) 6 | 7 | signature MAIN = 8 | sig 9 | val version : string 10 | val main : unit -> 'a 11 | end; 12 | -------------------------------------------------------------------------------- /basis/Position.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library 5 | * 6 | * Note: Kept transparent to avoid overloading complications. 7 | *) 8 | 9 | structure Position : INTEGER = Int; 10 | -------------------------------------------------------------------------------- /fix/TextIO.sml: -------------------------------------------------------------------------------- 1 | (* The type of inputLine changed. *) 2 | 3 | structure TextIO = 4 | struct 5 | open TextIO 6 | 7 | fun inputLine strm = 8 | case inputLine strm of 9 | "" => NONE 10 | | s => SOME s 11 | end 12 | -------------------------------------------------------------------------------- /main/wrap-poly.sml: -------------------------------------------------------------------------------- 1 | use "hamlet.sml"; 2 | use "main/MAIN-sig.sml"; 3 | use "main/Main.sml"; 4 | (* Need to flush stdOut to avoid ghost prompts appearing on HaMLet startup *) 5 | TextIO.flushOut TextIO.stdOut; PolyML.export("hamlet", Main.main); 6 | -------------------------------------------------------------------------------- /test/abstype2.sml: -------------------------------------------------------------------------------- 1 | (* abstype2.sml *) 2 | 3 | (* Checks equality inferred for abstype environments. *) 4 | 5 | (* THIS SHOULD PRODUCE A COMPILE TIME ERROR! *) 6 | 7 | abstype t = T with end 8 | 9 | fun eq(t1, t2 : t) = t1 = t2; 10 | -------------------------------------------------------------------------------- /test/fun-case.sml: -------------------------------------------------------------------------------- 1 | (* fun-case.sml *) 2 | 3 | (* Checks for parsing of "fun"/"case" combinations. *) 4 | 5 | (* HaMLet cannot deal with this example, currently *) 6 | 7 | fun f(x::xs) = case xs of (x::xs) => 2 | nil => 1 8 | | f nil = 0; 9 | -------------------------------------------------------------------------------- /test/semicolon.sml: -------------------------------------------------------------------------------- 1 | (* semicolon.sml *) 2 | 3 | (* Checks parsing of semicolons. *) 4 | 5 | structure A = struct ;;;;;;;; end; 6 | signature S = sig ;;;;;;;;;;; end; 7 | val _ = let ;;;;;;;;;;; in () end; 8 | 9 | ;;;;;;;;;;;;;;;; 10 | -------------------------------------------------------------------------------- /basis/COMMAND_LINE-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2013-2025 3 | * 4 | * Standard ML Basis Library 5 | *) 6 | 7 | signature COMMAND_LINE = 8 | sig 9 | val name : unit -> string 10 | val arguments : unit -> string list 11 | end; 12 | -------------------------------------------------------------------------------- /test/open.sml: -------------------------------------------------------------------------------- 1 | (* open.sml *) 2 | 3 | (* Checks scoping rules of open. *) 4 | 5 | structure A = struct structure B = struct val x = 1 end end 6 | structure B = struct val x = 0.1 end 7 | 8 | open A B 9 | 10 | val y = B.x + 1 11 | val z = x + 1.0; 12 | -------------------------------------------------------------------------------- /test/where2.sml: -------------------------------------------------------------------------------- 1 | (* where2.sml *) 2 | 3 | (* Checks if equality and constructor consistency is enforced for realisations. *) 4 | 5 | signature S1 = sig eqtype t end where type t = unit -> unit; 6 | signature S2 = sig datatype t = T end where type t = int * int; 7 | -------------------------------------------------------------------------------- /basis/infix.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library infix identifiers 5 | *) 6 | 7 | infix 7 * / div mod 8 | infix 6 + - ^ 9 | infixr 5 :: @ 10 | infix 4 = <> > >= < <= 11 | infix 3 := o 12 | infix 0 before; 13 | -------------------------------------------------------------------------------- /lib/USE-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library `use' function 5 | *) 6 | 7 | signature USE = 8 | sig 9 | val enqueue : string -> unit (* raises Path *) 10 | val extract : unit -> string option 11 | end; 12 | -------------------------------------------------------------------------------- /test/fun-partial.sml: -------------------------------------------------------------------------------- 1 | (* fun-partial.sml *) 2 | 3 | (* Checks for correct treatment of pattern matching in curried functions. *) 4 | 5 | (* Example due to Stephen Weeks. *) 6 | 7 | datatype t = A | B 8 | fun f A () = () 9 | val _ = f B (* should succeed *) 10 | -------------------------------------------------------------------------------- /test/generalise.sml: -------------------------------------------------------------------------------- 1 | (* generalise.sml *) 2 | 3 | (* Checks that types are properly generalised at value bindings. *) 4 | 5 | val f = fn x => x 6 | and r = ref 5 7 | and g = fn x => x; 8 | 9 | val 'a (r, _) = (ref 6, fn x : 'a => x); 10 | 11 | f 3; f "3"; 12 | g 4; g "4"; 13 | -------------------------------------------------------------------------------- /syntax/PP_MODULE-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2007-2025 3 | * 4 | * Printer for abstract module syntax 5 | *) 6 | 7 | signature PP_MODULE = 8 | sig 9 | type TopDec = SyntaxModule.TopDec 10 | 11 | val ppTopDec : TextIO.outstream * int * TopDec -> unit 12 | end; 13 | -------------------------------------------------------------------------------- /doc/README.txt: -------------------------------------------------------------------------------- 1 | All HaMLet sources (c) 1999-2025 Andreas Rossberg. 2 | 3 | Please see INSTALL.txt for brief instructions and the doc directory for 4 | the full documentation. See LICENSE.txt for licensing information. 5 | 6 | The HaMLet homepage is: 7 | 8 | http://www.mpi-sws.org/~rossberg/hamlet/ 9 | -------------------------------------------------------------------------------- /syntax/PP_PROGRAM-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2007-2025 3 | * 4 | * Printer for abstract program syntax 5 | *) 6 | 7 | signature PP_PROGRAM = 8 | sig 9 | type Program = SyntaxProgram.Program 10 | 11 | val ppProgram : TextIO.outstream * int * Program -> unit 12 | end; 13 | -------------------------------------------------------------------------------- /test/typespec.sml: -------------------------------------------------------------------------------- 1 | (* typespec.sml *) 2 | 3 | (* Checks scoping of definitional type specifications. *) 4 | 5 | type t = int 6 | 7 | signature S = 8 | sig 9 | type t = bool 10 | and u = t 11 | end 12 | 13 | structure X : S = 14 | struct 15 | type t = bool 16 | and u = bool 17 | end; 18 | -------------------------------------------------------------------------------- /basis/OS.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library 5 | * 6 | * Note: Incomplete. 7 | *) 8 | 9 | structure OS :> OS = 10 | struct 11 | open OS 12 | 13 | type syserror = int 14 | exception SysErr of string * syserror option (* defunct dummy *) 15 | end; 16 | -------------------------------------------------------------------------------- /test/abstype.sml: -------------------------------------------------------------------------------- 1 | (* abstype.sml *) 2 | 3 | (* Checks equality inferred for abstype environments. *) 4 | 5 | (* HaMLet cannot deal with eq2. *) 6 | 7 | abstype t = T with 8 | datatype u = U of t 9 | val eq = op= 10 | end 11 | 12 | fun eq1(t1, t2) = U t1 = U t2; 13 | fun eq2(t1, t2 : t) = eq(t1, t2); 14 | -------------------------------------------------------------------------------- /compile-js/PP_JS-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2013-2025 3 | * 4 | * Printer for JavaScript syntax 5 | *) 6 | 7 | signature PP_JS = 8 | sig 9 | val ppVar : JSSyntax.var -> PrettyPrint.doc 10 | val ppExpr : JSSyntax.expr -> PrettyPrint.doc 11 | val ppStmt : JSSyntax.stmt -> PrettyPrint.doc 12 | end; 13 | -------------------------------------------------------------------------------- /exec/PP_BASIS-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML pretty printing of the combined basis 5 | *) 6 | 7 | signature PP_BASIS = 8 | sig 9 | type Basis = Basis.Basis 10 | type State = DynamicObjectsCore.State 11 | 12 | val ppBasis : State * Basis -> PrettyPrint.doc 13 | end; 14 | -------------------------------------------------------------------------------- /test/overloading.sml: -------------------------------------------------------------------------------- 1 | (* overloading.sml *) 2 | 3 | (* Checks overloading resolution. *) 4 | 5 | fun f(x, y) = (x + y)/y 6 | fun g(x, y) = x/(x - y) 7 | 8 | val x = f(1.2, 2.3) + g(1.0, 2.0); 9 | 10 | fun f x = 11 | x + let 12 | fun g() = x 13 | in 14 | g() * 2.0 15 | end; 16 | -------------------------------------------------------------------------------- /basis/CommandLine.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2013-2025 3 | * 4 | * Standard ML Basis Library 5 | *) 6 | 7 | structure CommandLine : COMMAND_LINE = 8 | struct 9 | val name = use{b = "CommandLine.name"} : unit -> string 10 | val arguments = use{b = "CommandLine.arguments"} : unit -> string list 11 | end; 12 | -------------------------------------------------------------------------------- /fix/CharVector.sml: -------------------------------------------------------------------------------- 1 | (* CharVector.all is missing in Moscow ML *) 2 | 3 | structure CharVector = 4 | struct 5 | open CharVector 6 | 7 | local 8 | fun all'(p, s, i) = 9 | i = String.size s orelse p(String.sub(s, i)) andalso all'(p, s, i + 1) 10 | in 11 | fun all p s = all'(p, s, 0) 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | All HaMLet sources (c) 1999-2025 Andreas Rossberg. 2 | 3 | Please see [INSTALL.txt](doc/INSTALL.txt) for brief instructions and the doc directory for 4 | the full documentation. See [LICENSE.txt](doc/LICENSE.txt) for licensing information. 5 | 6 | The HaMLet homepage is: 7 | 8 | http://www.mpi-sws.org/~rossberg/hamlet/ 9 | -------------------------------------------------------------------------------- /eval/PP_DYNAMIC_BASIS-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML pretty printing of the dynamic basis 5 | *) 6 | 7 | signature PP_DYNAMIC_BASIS = 8 | sig 9 | type Basis = DynamicObjectsModule.Basis 10 | type State = DynamicObjectsCore.State 11 | 12 | val ppBasis : State * Basis -> PrettyPrint.doc 13 | end; 14 | -------------------------------------------------------------------------------- /main/wrap-smlnj.sml: -------------------------------------------------------------------------------- 1 | SMLofNJ.Internals.GC.messages false; 2 | 3 | (* Ugliest hack to support built with old and new CM (SML/NJ >= 110.20) *) 4 | CM.make(Unsafe.cast "sources.cm"); 5 | 6 | (* Force built-time evaluation of basis lib *) 7 | (*Sml.parseString ";";*) 8 | 9 | (* Export *) 10 | SMLofNJ.exportFn ("hamlet-image", Main.main o ignore); 11 | -------------------------------------------------------------------------------- /parse/INITIAL_INFIX_ENV-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML initial infix environment 5 | * 6 | * Definition, Appendix C 7 | *) 8 | 9 | signature INITIAL_INFIX_ENV = 10 | sig 11 | (* Import type *) 12 | 13 | type InfEnv = Infix.InfEnv 14 | 15 | (* Export *) 16 | 17 | val J0 : InfEnv 18 | end; 19 | -------------------------------------------------------------------------------- /fix/OS.sml: -------------------------------------------------------------------------------- 1 | (* OS.Path.mk{Absolute,Relative} changed signature *) 2 | 3 | structure OS = 4 | struct 5 | open OS 6 | 7 | structure Path = 8 | struct 9 | open Path 10 | 11 | fun mkAbsolute{path, relativeTo} = Path.mkAbsolute(path, relativeTo) 12 | fun mkRelative{path, relativeTo} = Path.mkRelative(path, relativeTo) 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /smlnj-lib/ord-key-sig.sml: -------------------------------------------------------------------------------- 1 | (* ord-key-sig.sml 2 | * 3 | * COPYRIGHT (c) 1993 by AT&T Bell Laboratories. See COPYRIGHT file for details. 4 | * 5 | * Abstract linearly ordered keys. 6 | * 7 | *) 8 | 9 | signature ORD_KEY = 10 | sig 11 | type ord_key 12 | 13 | val compare : ord_key * ord_key -> order 14 | 15 | end (* ORD_KEY *) 16 | ; 17 | -------------------------------------------------------------------------------- /test/undetermined.sml: -------------------------------------------------------------------------------- 1 | (* undetermined.sml *) 2 | 3 | (* Checks inference for non-generalised types (aka "free type variables"). *) 4 | 5 | val a = ref nil 6 | val _ = a := [1]; 7 | 8 | structure A : sig val a : int list ref end = 9 | struct 10 | val a = ref nil 11 | end; 12 | 13 | structure B : sig end = 14 | struct 15 | val a = ref nil 16 | end; 17 | -------------------------------------------------------------------------------- /elab/INITIAL_STATIC_BASIS-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML initial static basis 5 | * 6 | * Definition, Appendices C and E 7 | *) 8 | 9 | signature INITIAL_STATIC_BASIS = 10 | sig 11 | (* Import *) 12 | 13 | type Basis = StaticObjectsModule.Basis 14 | 15 | (* Export *) 16 | 17 | val B0 : Basis 18 | end; 19 | -------------------------------------------------------------------------------- /exec/PP_ENV-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML pretty printing of the combined static/dynamic environment 5 | *) 6 | 7 | signature PP_ENV = 8 | sig 9 | type Env = StaticObjectsCore.Env * DynamicObjectsCore.Env 10 | type State = DynamicObjectsCore.State 11 | 12 | val ppEnv : State * Env -> PrettyPrint.doc 13 | end; 14 | -------------------------------------------------------------------------------- /test/id.sml: -------------------------------------------------------------------------------- 1 | (* id.sml *) 2 | 3 | (* Checks parsing of identifiers. *) 4 | 5 | val ? = {* = op*, + = op+} 6 | val op* = # * ? 7 | val op+ = # + ?; 8 | 9 | type '1 t = unit 10 | type '& = ' list 11 | type t = int& 12 | type ''`` = '' 13 | type ('0, '_) == = '_`` &; 14 | 15 | fun !x=x=x 16 | fun ''`x:''=(x=x;x); 17 | 18 | infix v 19 | fun 3v? = 0 20 | | _v? = 1; 21 | -------------------------------------------------------------------------------- /fix/CommandLine-smlsharp.sml: -------------------------------------------------------------------------------- 1 | (* Under SML# we don't want to know the location of the runtime, 2 | * but need to know the image path so that we find the basis lib. 3 | * For now, we fake it with the CWD. *) 4 | 5 | structure CommandLine : COMMAND_LINE = 6 | struct 7 | val arguments = CommandLine.arguments 8 | 9 | fun name() = OS.FileSys.getDir() ^ "/hamlet" 10 | end 11 | -------------------------------------------------------------------------------- /test/poly-exception.sml: -------------------------------------------------------------------------------- 1 | (* poly-exception.sml *) 2 | 3 | (* Checks whether type variables are allowed with local exception declartions. *) 4 | 5 | fun f x = let exception E of 'a in E end; 6 | val x = let exception E of 'a in () end; 7 | val _ = let exception E of 'a in E end; 8 | 9 | local exception E of 'a in end; 10 | structure S : sig end = struct exception E of 'a end; 11 | -------------------------------------------------------------------------------- /compile-js/JS_TRANSLATE_SCON-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2013-2025 3 | * 4 | * Translation of special constants into JavaScript. 5 | *) 6 | 7 | signature JS_TRANSLATE_SCON = 8 | sig 9 | (* Import *) 10 | 11 | type SCon = SyntaxCore.SCon 12 | 13 | type expr = JSSyntax.expr 14 | 15 | 16 | (* Export *) 17 | 18 | val translateSCon : SCon -> expr 19 | end; 20 | -------------------------------------------------------------------------------- /fix/Makefile.depend.in: -------------------------------------------------------------------------------- 1 | # System-specific library work-arounds 2 | Char-$(SYSTEM).$(EXT) : 3 | CharVector-$(SYSTEM).$(EXT) : 4 | CommandLine-$(SYSTEM).$(EXT) : 5 | Large-$(SYSTEM).$(EXT) : 6 | ListPair-$(SYSTEM).$(EXT) : 7 | OS-$(SYSTEM).$(EXT) : 8 | String-$(SYSTEM).$(EXT) : Char-$(SYSTEM).$(EXT) 9 | Real-$(SYSTEM).$(EXT) : 10 | TextIO-$(SYSTEM).$(EXT) : 11 | Word-$(SYSTEM).$(EXT) : 12 | -------------------------------------------------------------------------------- /basis/Word8Vector.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library 5 | * 6 | * Note: Kept transparent to allow easy implementation of Word8VectorSlice. 7 | *) 8 | 9 | structure Word8Vector : MONO_VECTOR 10 | where type elem = Word8.word = 11 | struct 12 | open Vector 13 | 14 | type elem = Word8.word 15 | type vector = elem vector 16 | end; 17 | -------------------------------------------------------------------------------- /eval/PP_DYNAMIC_ENV-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML pretty printing of the dynamic environment 5 | *) 6 | 7 | signature PP_DYNAMIC_ENV = 8 | sig 9 | type Env = DynamicObjectsCore.Env 10 | type State = DynamicObjectsCore.State 11 | 12 | val ppEnv : State * Env -> PrettyPrint.doc 13 | val ppStr : State * Env -> PrettyPrint.doc 14 | end; 15 | -------------------------------------------------------------------------------- /infrastructure/STAMP-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Stamp generator. 5 | *) 6 | 7 | signature STAMP = 8 | sig 9 | eqtype stamp 10 | 11 | val stamp : unit -> stamp 12 | val toString : stamp -> string 13 | 14 | val reset : unit -> unit 15 | 16 | val compare : stamp * stamp -> order 17 | val min : stamp * stamp -> stamp 18 | end; 19 | -------------------------------------------------------------------------------- /elab/PP_TYPE-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML pretty printing of types and type schemes 5 | *) 6 | 7 | signature PP_TYPE = 8 | sig 9 | type Type = StaticObjectsCore.Type 10 | type TypeScheme = StaticObjectsCore.TypeScheme 11 | 12 | val ppType : Type -> PrettyPrint.doc 13 | val ppTypeScheme : TypeScheme -> PrettyPrint.doc 14 | end; 15 | -------------------------------------------------------------------------------- /elab/SCOPE_TYVARS-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML scope of type variables 5 | * 6 | * Definition, Section 4.6 7 | *) 8 | 9 | signature SCOPE_TYVARS = 10 | sig 11 | (* Import *) 12 | 13 | type ValBind = SyntaxCore.ValBind 14 | type TyVarSet = TyVarSet.set 15 | 16 | (* Operation *) 17 | 18 | val unguardedTyVars : ValBind -> TyVarSet 19 | end; 20 | -------------------------------------------------------------------------------- /eval/ADDR-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML addresses 5 | * 6 | * Definition, Section 6.2 7 | *) 8 | 9 | signature ADDR = 10 | sig 11 | (* Type [Section 6.2] *) 12 | 13 | eqtype Addr (* [a] *) 14 | 15 | 16 | (* Operations *) 17 | 18 | val addr : unit -> Addr 19 | val compare : Addr * Addr -> order 20 | end; 21 | -------------------------------------------------------------------------------- /syntax/IDSTATUS-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML identifier status 5 | * 6 | * Definition, Sections 4.1 and 5.5 7 | *) 8 | 9 | signature IDSTATUS = 10 | sig 11 | (* Type [Section 4.1] *) 12 | 13 | datatype IdStatus = c | e | v (* [is] *) 14 | 15 | (* Operations *) 16 | 17 | val generalises : IdStatus * IdStatus -> bool 18 | end; 19 | -------------------------------------------------------------------------------- /parse/BINDING_ENV-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML environment for binding analysis 5 | *) 6 | 7 | signature BINDING_ENV = 8 | sig 9 | (* Inheritance *) 10 | 11 | include GENERIC_ENV 12 | where type Env = BindingObjectsCore.Env 13 | and type ValStr = BindingObjectsCore.IdStatus 14 | and type TyStr = BindingObjectsCore.ValEnv 15 | end; 16 | -------------------------------------------------------------------------------- /parse/PARSE-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML syntactic analysis 5 | *) 6 | 7 | signature PARSE = 8 | sig 9 | (* Import *) 10 | 11 | type source = Source.source 12 | type InfEnv = Infix.InfEnv 13 | type Program = SyntaxProgram.Program 14 | 15 | 16 | (* Export *) 17 | 18 | val parse : InfEnv * source * string option -> InfEnv * Program 19 | end; 20 | -------------------------------------------------------------------------------- /test/undetermined3.sml: -------------------------------------------------------------------------------- 1 | (* undetermined3.sml *) 2 | 3 | (* Checks that matching undetermined types does not perform unsound unification. 4 | Example due to Stephen Weeks. 5 | *) 6 | 7 | (* HAS TO BE REJECTED! *) 8 | 9 | signature S = sig val f : 'a -> 'a option end 10 | structure X : S = 11 | struct 12 | fun g() = let val r = ref NONE in fn x => !r before r := SOME x end 13 | val f = g() 14 | end; 15 | -------------------------------------------------------------------------------- /basis/Word8VectorSlice.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2002-2025 3 | * 4 | * Standard ML Basis Library 5 | *) 6 | 7 | structure Word8VectorSlice :> MONO_VECTOR_SLICE 8 | where type vector = Word8Vector.vector 9 | where type elem = Word8.word = 10 | struct 11 | open VectorSlice 12 | 13 | type elem = Word8.word 14 | type vector = Word8Vector.vector 15 | type slice = elem slice 16 | end; 17 | -------------------------------------------------------------------------------- /compile-js/JS_TRANSLATE_PROGRAM-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2013-2025 3 | * 4 | * Translation of programs into JavaScript. 5 | *) 6 | 7 | signature JS_TRANSLATE_PROGRAM = 8 | sig 9 | (* Import *) 10 | 11 | type Program = SyntaxProgram.Program 12 | 13 | type stmt = JSSyntax.stmt 14 | 15 | (* Export *) 16 | 17 | val translateProgram : StaticBasis.Basis * Program -> stmt list 18 | end; 19 | -------------------------------------------------------------------------------- /eval/PP_VAL-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML pretty printing of values 5 | *) 6 | 7 | signature PP_VAL = 8 | sig 9 | type Val = DynamicObjectsCore.Val 10 | type ExVal = DynamicObjectsCore.ExVal 11 | type State = DynamicObjectsCore.State 12 | 13 | val ppVal : State * Val -> PrettyPrint.doc 14 | val ppExVal : State * ExVal -> PrettyPrint.doc 15 | end; 16 | -------------------------------------------------------------------------------- /valid/SCOPE_TYVARS-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML scope of type variables 5 | * 6 | * Definition, Section 4.6 7 | *) 8 | 9 | signature SCOPE_TYVARS = 10 | sig 11 | (* Import *) 12 | 13 | type ValBind = SyntaxCore.ValBind 14 | type TyVarSet = TyVarSet.set 15 | 16 | (* Operation *) 17 | 18 | val unguardedTyVars : ValBind -> TyVarSet 19 | end; 20 | -------------------------------------------------------------------------------- /basis/IO.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library 5 | *) 6 | 7 | structure IO :> IO = 8 | struct 9 | exception Io = IO.Io (* primitive *) 10 | 11 | exception BlockingNotSupported 12 | exception NonblockingNotSupported 13 | exception RandomAccessNotSupported 14 | exception ClosedStream 15 | 16 | datatype buffer_mode = NO_BUF | LINE_BUF | BLOCK_BUF 17 | end; 18 | -------------------------------------------------------------------------------- /elab/ELAB_MODULE-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML modules elaboration 5 | * 6 | * Definition, Sections 5.7 and 3.5 7 | *) 8 | 9 | signature ELAB_MODULE = 10 | sig 11 | (* Import types *) 12 | 13 | type TopDec = SyntaxModule.TopDec 14 | type Basis = StaticObjectsModule.Basis 15 | 16 | (* Export *) 17 | 18 | val elabTopDec : Basis * TopDec -> Basis 19 | end; 20 | -------------------------------------------------------------------------------- /basis/IO-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library 5 | *) 6 | 7 | signature IO = 8 | sig 9 | exception Io of {name : string, function : string, cause : exn} 10 | exception BlockingNotSupported 11 | exception NonblockingNotSupported 12 | exception RandomAccessNotSupported 13 | exception ClosedStream 14 | datatype buffer_mode = NO_BUF | LINE_BUF | BLOCK_BUF 15 | end; 16 | -------------------------------------------------------------------------------- /compile-js/COMPILE_JS-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2013-2025 3 | * 4 | * Translation of programs into JavaScript. 5 | *) 6 | 7 | signature COMPILE_JS = 8 | sig 9 | (* Import *) 10 | 11 | type Program = SyntaxProgram.Program 12 | type StaticBasis = StaticObjectsModule.Basis 13 | 14 | (* Export *) 15 | 16 | val compileProgram : TextIO.outstream -> StaticBasis * Program -> StaticBasis 17 | end; 18 | -------------------------------------------------------------------------------- /parse/SYNTACTIC_RESTRICTIONS_PROGRAM-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML syntactic restrictions for programs 5 | *) 6 | 7 | signature SYNTACTIC_RESTRICTIONS_PROGRAM = 8 | sig 9 | (* Import *) 10 | 11 | type Basis = SyntacticRestrictionsModule.Basis 12 | type Program = SyntaxProgram.Program 13 | 14 | (* Export *) 15 | 16 | val checkProgram : Basis * Program -> Basis 17 | end; 18 | -------------------------------------------------------------------------------- /valid/VALID_MODULE-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML modules elaboration 5 | * 6 | * Definition, Sections 5.7 and 3.5 7 | *) 8 | 9 | signature VALID_MODULE = 10 | sig 11 | (* Import types *) 12 | 13 | type TopDec = SyntaxModule.TopDec 14 | type Basis = StaticObjectsModule.Basis 15 | 16 | (* Export *) 17 | 18 | val validTopDec : Basis * TopDec -> Basis 19 | end; 20 | -------------------------------------------------------------------------------- /syntax/IdStatus.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML identifier status 5 | * 6 | * Definition, Sections 4.1 and 5.5 7 | *) 8 | 9 | structure IdStatus :> IDSTATUS = 10 | struct 11 | (* Type [Section 4.1] *) 12 | 13 | datatype IdStatus = c | e | v (* [is] *) 14 | 15 | (* Generalisation [Section 5.5] *) 16 | 17 | fun generalises(is1, is2) = is1 = is2 orelse is2 = v 18 | end; 19 | -------------------------------------------------------------------------------- /fix/Word.sml: -------------------------------------------------------------------------------- 1 | (* For non-up-to-date systems *) 2 | 3 | structure Word = 4 | struct 5 | open Word 6 | 7 | fun ~w = 0w0-w 8 | val fromLarge = fromLargeWord 9 | val toLarge = toLargeWord 10 | val toLargeX = toLargeWordX 11 | end 12 | 13 | structure Word8 = 14 | struct 15 | open Word8 16 | 17 | fun ~w = 0w0-w 18 | val fromLarge = fromLargeWord 19 | val toLarge = toLargeWord 20 | val toLargeX = toLargeWordX 21 | end 22 | -------------------------------------------------------------------------------- /basis/TEXT_STREAM_IO-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library 5 | * 6 | * Note: Incomplete. 7 | *) 8 | 9 | signature TEXT_STREAM_IO = 10 | sig 11 | include STREAM_IO 12 | where type vector = CharVector.vector 13 | where type elem = Char.char 14 | (* 15 | val inputLine : instream -> (string * instream) option 16 | val outputSubstr : outstream * substring -> unit 17 | *) 18 | end; 19 | -------------------------------------------------------------------------------- /parse/SYNTACTIC_RESTRICTIONS_MODULE-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML syntactic restrictions for modules 5 | * 6 | * Definition, Section 3.5 7 | *) 8 | 9 | signature SYNTACTIC_RESTRICTIONS_MODULE = 10 | sig 11 | (* Import *) 12 | 13 | type Basis = BindingObjectsModule.Basis 14 | type TopDec = SyntaxModule.TopDec 15 | 16 | (* Export *) 17 | 18 | val checkTopDec : Basis * TopDec -> Basis 19 | end; 20 | -------------------------------------------------------------------------------- /parse/BindingEnv.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML environment for binding analysis 5 | *) 6 | 7 | structure BindingEnv : BINDING_ENV = 8 | struct 9 | (* Inheritance *) 10 | 11 | structure GenericEnv = 12 | GenericEnvFn( 13 | open BindingObjectsCore 14 | type ValStr = IdStatus 15 | type TyStr = ValEnv 16 | fun unEnv(Env E) = E 17 | ) 18 | 19 | open GenericEnv 20 | end; 21 | -------------------------------------------------------------------------------- /basis/BOOL-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library 5 | *) 6 | 7 | structure StringCvt = struct type ('a, 'b) reader = 'b -> ('a * 'b) option end 8 | 9 | signature BOOL = 10 | sig 11 | datatype bool = datatype bool 12 | val not : bool -> bool 13 | val scan : (char, 'a) StringCvt.reader -> (bool, 'a) StringCvt.reader 14 | val fromString : string -> bool option 15 | val toString : bool -> string 16 | end; 17 | -------------------------------------------------------------------------------- /basis/OS_Process.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2013-2025 3 | * 4 | * Standard ML Basis Library 5 | *) 6 | 7 | structure OS = 8 | struct 9 | open OS 10 | 11 | structure Process :> OS_PROCESS = 12 | struct 13 | type status = int 14 | 15 | val success = 0 16 | val failure = 1 17 | 18 | fun isSuccess st = st = 0 19 | fun terminate st = (use{b = "OS.Process.terminate"} : status -> 'a) st 20 | val exit = terminate 21 | end 22 | end; 23 | -------------------------------------------------------------------------------- /basis/exceptions.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library top-level exceptions 5 | *) 6 | 7 | exception Bind = Bind 8 | exception Chr = Chr 9 | exception Div = Div 10 | exception Domain = Domain 11 | exception Match = Match 12 | exception Overflow = Overflow 13 | exception Size = Size 14 | exception Subscript = Subscript 15 | 16 | exception Empty 17 | exception Fail of string 18 | exception Span; 19 | -------------------------------------------------------------------------------- /elab/CLOS-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML closure of value environments 5 | * 6 | * Definition, Section 4.7 and 4.8 7 | *) 8 | 9 | signature CLOS = 10 | sig 11 | (* Import *) 12 | 13 | type ValBind = SyntaxCore.ValBind 14 | type ValEnv = StaticObjectsCore.ValEnv 15 | 16 | type Context = StaticObjectsCore.Context 17 | 18 | 19 | (* Operation *) 20 | 21 | val Clos : Context * ValBind -> ValEnv -> ValEnv 22 | end; 23 | -------------------------------------------------------------------------------- /eval/INITIAL_DYNAMIC_BASIS-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML initial dynamic basis 5 | * 6 | * Definition, Appendix D 7 | * 8 | * Note: see INITIAL_DYNAMIC_ENV-sig.sml 9 | *) 10 | 11 | signature INITIAL_DYNAMIC_BASIS = 12 | sig 13 | (* Import *) 14 | 15 | type Basis = DynamicObjectsModule.Basis 16 | type State = DynamicObjectsCore.State 17 | 18 | 19 | (* Export *) 20 | 21 | val B0 : Basis 22 | val s0 : State 23 | end; 24 | -------------------------------------------------------------------------------- /elab/PP_STATIC_BASIS-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML pretty printing of the static basis 5 | *) 6 | 7 | signature PP_STATIC_BASIS = 8 | sig 9 | type Basis = StaticObjectsModule.Basis 10 | type SigEnv = StaticObjectsModule.SigEnv 11 | type FunEnv = StaticObjectsModule.FunEnv 12 | 13 | val ppBasis : Basis -> PrettyPrint.doc 14 | val ppSigEnv : SigEnv -> PrettyPrint.doc 15 | val ppFunEnv : FunEnv -> PrettyPrint.doc 16 | end; 17 | -------------------------------------------------------------------------------- /syntax/PPProgram.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2007-2025 3 | * 4 | * Printer for abstract program syntax 5 | *) 6 | 7 | structure PPProgram : PP_PROGRAM = 8 | struct 9 | (* Import *) 10 | 11 | open SyntaxProgram 12 | open Annotation 13 | open PPSyntax 14 | 15 | (* Programs *) 16 | 17 | fun ppProgram(out, i, Program(topdec, program_opt)@@A) = 18 | ppElem(out, i, "Program", A, 19 | [sub PPModule.ppTopDec topdec, subo ppProgram program_opt]) 20 | end; 21 | -------------------------------------------------------------------------------- /test/scon.sml: -------------------------------------------------------------------------------- 1 | (* scon *) 2 | 3 | (* Checks parsing of special constants. *) 4 | 5 | (* Note that the (**)-marked expressions may raise a runtime error even 6 | * in HaMLet due to broken implementations of {Char,Real}.scan in the host 7 | * system. *) 8 | 9 | #"\^C"; 10 | #"\a"; 11 | #"\u0000"; (**) 12 | #"\ \x\ \"; 13 | 3.2121212121212121212121212121; 14 | 2e3; 15 | 0.00000000000e123213213123213123123; (**) 16 | 0wxabcd; 17 | 0xAaAa; 18 | -------------------------------------------------------------------------------- /infrastructure/FIN_SET-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML finite sets 5 | * 6 | * Definition, Section 4.2 7 | * 8 | * Note: This signature just extends the one available in the SML/NJ lib. 9 | *) 10 | 11 | signature FIN_SET = 12 | sig 13 | include ORD_SET 14 | 15 | exception NotFound 16 | 17 | val fromList : item list -> set 18 | 19 | val first : set -> item option (* raises NotFound *) 20 | val disjoint : set * set -> bool 21 | end; 22 | -------------------------------------------------------------------------------- /infrastructure/Stamp.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Stamp generator. 5 | *) 6 | 7 | structure Stamp :> STAMP = 8 | struct 9 | type stamp = int 10 | 11 | val r = ref 0 12 | 13 | fun reset() = r := 0 14 | fun stamp() = (r := !r + 1; !r) 15 | 16 | val toString = Int.toString 17 | val compare = Int.compare 18 | val min = Int.min 19 | end 20 | 21 | structure StampMap = 22 | FinMapFn(type ord_key = Stamp.stamp; val compare = Stamp.compare); 23 | -------------------------------------------------------------------------------- /eval/EVAL_MODULE-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML modules evaluation 5 | * 6 | * Definition, Section 7.3 7 | * 8 | * Notes: see EVAL_CORE-sig.sml 9 | *) 10 | 11 | signature EVAL_MODULE = 12 | sig 13 | (* Import types *) 14 | 15 | type TopDec = SyntaxModule.TopDec 16 | type Basis = DynamicObjectsModule.Basis 17 | type State = EvalCore.State 18 | 19 | (* Export *) 20 | 21 | val evalTopDec : (State ref * Basis) * TopDec -> Basis 22 | end; 23 | -------------------------------------------------------------------------------- /basis/Word8Array.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library 5 | * 6 | * Note: 7 | * Array type kept transparent to allow trivial implementation of 8 | * Word8ArraySlice. 9 | *) 10 | 11 | structure Word8Array : MONO_ARRAY 12 | where type vector = Word8Vector.vector 13 | where type elem = Word8.word = 14 | struct 15 | open Array 16 | 17 | type elem = Word8.word 18 | type vector = Word8Vector.vector 19 | type array = elem array 20 | end; 21 | -------------------------------------------------------------------------------- /eval/BASVAL-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML basic values 5 | * 6 | * Definition, Section 6.4 7 | *) 8 | 9 | signature BASVAL = 10 | sig 11 | (* Import *) 12 | 13 | type BasVal = DynamicObjectsCore.BasVal 14 | type Val = DynamicObjectsCore.Val 15 | 16 | 17 | (* Operations *) 18 | 19 | exception TypeError of string 20 | 21 | val APPLY : BasVal * Val -> Val (* raises Pack TypeError *) 22 | 23 | val toString : BasVal -> string 24 | end; 25 | -------------------------------------------------------------------------------- /test/replication.sml: -------------------------------------------------------------------------------- 1 | (* replication.sml *) 2 | 3 | (* Checks semantics of datatype replication. *) 4 | 5 | type u = int 6 | datatype v = datatype u 7 | 8 | val A = 0 : v 9 | 10 | structure X = 11 | struct 12 | datatype t = A 13 | end 14 | 15 | structure Y = 16 | struct 17 | type u = X.t 18 | datatype v = datatype u 19 | val n = A + 1 20 | end 21 | 22 | functor F(type t) = 23 | struct 24 | datatype u = datatype t 25 | val A = A + 1 26 | end 27 | 28 | structure Z = F(datatype t = A); 29 | -------------------------------------------------------------------------------- /fix/Large.sml: -------------------------------------------------------------------------------- 1 | (* Large types are missing in Moscow ML *) 2 | 3 | structure Word = 4 | struct 5 | open Word 6 | fun fromLarge i = i 7 | fun toLarge i = i 8 | end 9 | 10 | structure Real = 11 | struct 12 | open Real 13 | fun fromLarge _ r = r 14 | fun toLarge r = r 15 | end 16 | 17 | structure LargeInt = Int 18 | structure LargeWord = Word 19 | structure LargeReal = Real 20 | 21 | structure IEEEReal = 22 | struct 23 | datatype rounding_mode = TO_NEAREST | TO_NEGINF | TO_POSINF | TO_ZERO 24 | end 25 | -------------------------------------------------------------------------------- /syntax/SOURCE-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Helpers for handling source strings 5 | *) 6 | 7 | signature SOURCE = 8 | sig 9 | type source = string 10 | type pos = int * int 11 | type region = pos * pos 12 | type loc = {file : string option, region : region} 13 | 14 | val nowhere : loc 15 | val at : loc -> loc 16 | val left : loc -> loc 17 | val right : loc -> loc 18 | val over : loc * loc -> loc 19 | 20 | val compare : loc * loc -> order 21 | end; 22 | -------------------------------------------------------------------------------- /basis/BYTE-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2002-2025 3 | * 4 | * Standard ML Basis Library 5 | *) 6 | 7 | signature BYTE = 8 | sig 9 | val byteToChar : Word8.word -> char 10 | val charToByte : char -> Word8.word 11 | val bytesToString : Word8Vector.vector -> string 12 | val stringToBytes : string -> Word8Vector.vector 13 | val unpackStringVec : Word8VectorSlice.slice -> string 14 | val unpackString : Word8ArraySlice.slice -> string 15 | val packString : Word8Array.array * int * substring -> unit 16 | end; 17 | -------------------------------------------------------------------------------- /basis/OS_PROCESS-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2013-2025 3 | * 4 | * Standard ML Basis Library 5 | *) 6 | 7 | signature OS_PROCESS = 8 | sig 9 | type status 10 | val success : status 11 | val failure : status 12 | val isSuccess : status -> bool 13 | (* 14 | val system : string -> status 15 | val atExit : (unit -> unit) -> unit 16 | *) 17 | val exit : status -> 'a 18 | val terminate : status -> 'a 19 | (* 20 | val getEnv : string -> string option 21 | val sleep : Time.time -> unit 22 | *) 23 | end; 24 | -------------------------------------------------------------------------------- /eval/EXNAME-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML exception names 5 | * 6 | * Definition, Section 6.2 7 | *) 8 | 9 | signature EXNAME = 10 | sig 11 | (* Import *) 12 | 13 | type VId = VId.Id 14 | 15 | 16 | (* Type [Section 6.2] *) 17 | 18 | eqtype ExName (* [en] *) 19 | 20 | 21 | (* Operations *) 22 | 23 | val exname : VId -> ExName 24 | val toString : ExName -> string 25 | 26 | val compare : ExName * ExName -> order 27 | end; 28 | -------------------------------------------------------------------------------- /elab/InitialStaticBasis.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML initial static basis 5 | * 6 | * Definition, Appendices C and E 7 | *) 8 | 9 | structure InitialStaticBasis : INITIAL_STATIC_BASIS = 10 | struct 11 | (* Import *) 12 | 13 | type Basis = StaticObjectsModule.Basis 14 | 15 | 16 | (* Environments *) 17 | 18 | val T0 = InitialStaticEnv.T0 19 | val F0 = FunIdMap.empty 20 | val G0 = SigIdMap.empty 21 | val E0 = InitialStaticEnv.E0 22 | 23 | val B0 = (T0, F0, G0, E0) 24 | end; 25 | -------------------------------------------------------------------------------- /eval/Addr.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML addresses and maps thereof 5 | * 6 | * Definition, Sections 6.2 and 6.3 7 | *) 8 | 9 | structure Addr :> ADDR = 10 | struct 11 | (* Type [Section 6.2] *) 12 | 13 | type Addr = Stamp.stamp (* [a] *) 14 | 15 | (* Operations *) 16 | 17 | val addr = Stamp.stamp 18 | val compare = Stamp.compare 19 | end 20 | 21 | structure AddrMap = 22 | FinMapFn(type ord_key = Addr.Addr; val compare = Addr.compare); 23 | -------------------------------------------------------------------------------- /eval/DYNAMIC_ENV-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML environments of the dynamic semantics of the core 5 | * 6 | * Definition, Sections 6.3 and 6.6 7 | *) 8 | 9 | signature DYNAMIC_ENV = 10 | sig 11 | (* Inheritance *) 12 | 13 | include GENERIC_ENV 14 | where type Env = DynamicObjectsCore.Env 15 | and type ValStr = DynamicObjectsCore.ValStr 16 | and type TyStr = DynamicObjectsCore.ValEnv 17 | 18 | 19 | (* Operations *) 20 | 21 | val Rec : ValEnv -> ValEnv 22 | end; 23 | -------------------------------------------------------------------------------- /infrastructure/PROP-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2013-2025 3 | * 4 | * Property lists 5 | *) 6 | 7 | signature PROP = 8 | sig 9 | type nil 10 | type ('a, 'b) cons 11 | type 'a prop 12 | 13 | val none : nil 14 | val new : unit -> ('a, 'b) cons 15 | val hd : ('a, 'b) cons -> 'a prop 16 | val tl : ('a, ('b, 'c) cons) cons -> ('b, 'c) cons 17 | 18 | val has : 'a prop -> bool 19 | val try : 'a prop -> 'a option 20 | val get : 'a prop -> 'a (* raises Option *) 21 | val set : 'a prop * 'a -> unit 22 | end; 23 | -------------------------------------------------------------------------------- /syntax/LAB-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML label identifiers 5 | * 6 | * Definition, Section 2.4 7 | *) 8 | 9 | signature LAB = 10 | sig 11 | (* Type [Section 2.4] *) 12 | 13 | eqtype Lab (* [lab] *) 14 | 15 | 16 | (* Operations *) 17 | 18 | val fromString : string -> Lab 19 | val fromInt : int -> Lab 20 | val toString : Lab -> string 21 | val toInt : Lab -> int option 22 | 23 | val compare : Lab * Lab -> order 24 | end; 25 | -------------------------------------------------------------------------------- /test/undetermined2.sml: -------------------------------------------------------------------------------- 1 | (* undetermined2.sml *) 2 | 3 | (* Checks inference for non-generalised types (aka "free type variables"). *) 4 | 5 | (* The intention of the Definition is to reject these, but due to a 6 | misconception in the formalisation they actually have to be accepted, 7 | as far as the formal rules are concerned. *) 8 | 9 | val a = ref nil; 10 | val _ = a := [1]; 11 | 12 | val a = ref nil; 13 | structure X = struct end; 14 | val _ = a := [1]; 15 | 16 | val a = ref nil; 17 | signature S = sig end; 18 | val _ = a := [1]; 19 | -------------------------------------------------------------------------------- /basis/OS-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library 5 | * 6 | * Note: Incomplete. 7 | *) 8 | 9 | signature OS = 10 | sig 11 | structure FileSys : OS_FILE_SYS 12 | structure Path : OS_PATH 13 | structure Process : OS_PROCESS 14 | (* 15 | structure IO : OS_IO 16 | *) 17 | eqtype syserror 18 | exception SysErr of string * syserror option 19 | (* 20 | val errorMsg : syserror -> string 21 | val errorName : syserror -> string 22 | val syserror : string -> syserror option 23 | *) 24 | end; 25 | -------------------------------------------------------------------------------- /infrastructure/FinSetFn.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML finite sets 5 | * 6 | * Definition, Section 4.2 7 | *) 8 | 9 | functor FinSetFn(Key : ORD_KEY) :> 10 | FIN_SET where type Key.ord_key = Key.ord_key = 11 | struct 12 | structure BinarySet = BinarySetFn(Key) 13 | open BinarySet 14 | 15 | exception NotFound = LibBase.NotFound 16 | 17 | fun fromList xs = addList(empty, xs) 18 | 19 | fun first s = find (fn x => true) s 20 | fun disjoint(s1, s2) = isEmpty(intersection(s1, s2)) 21 | end; 22 | -------------------------------------------------------------------------------- /elab/FUNSIG-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML functor signatures 5 | * 6 | * Definition, Sections 5.1 and 5.4 7 | *) 8 | 9 | signature FUNSIG = 10 | sig 11 | (* Import *) 12 | 13 | type TyVarSet = StaticObjectsCore.TyVarSet 14 | type TyNameSet = StaticObjectsCore.TyNameSet 15 | type FunSig = StaticObjectsModule.FunSig 16 | 17 | 18 | (* Operations *) 19 | 20 | val tyvars : FunSig -> TyVarSet 21 | val tynames : FunSig -> TyNameSet 22 | val undetermined : FunSig -> bool StampMap.map 23 | end; 24 | -------------------------------------------------------------------------------- /syntax/SCON-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML special constants 5 | * 6 | * Definition, Section 2.2 7 | *) 8 | 9 | signature SCON = 10 | sig 11 | (* Types [Section 2.2] *) 12 | 13 | datatype base = DEC | HEX 14 | 15 | datatype SCon = (* [scon] *) 16 | INT of base * string 17 | | WORD of base * string 18 | | STRING of string 19 | | CHAR of string 20 | | REAL of string 21 | 22 | 23 | (* Operations *) 24 | 25 | val toString : SCon -> string 26 | end; 27 | -------------------------------------------------------------------------------- /parse/DERIVED_FORMS_PROGRAM-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML program derived forms 5 | * 6 | * Definition, Appendix A 7 | *) 8 | 9 | signature DERIVED_FORMS_PROGRAM = 10 | sig 11 | (* Import *) 12 | 13 | type Exp = SyntaxCore.Exp 14 | type TopDec = SyntaxModule.TopDec 15 | type Program = SyntaxProgram.Program 16 | 17 | (* Programs [Figure 18] *) 18 | 19 | val TOPDECProgram : TopDec * Program option -> SyntaxProgram.Program' 20 | val EXPProgram : Exp * Program option -> SyntaxProgram.Program' 21 | end; 22 | -------------------------------------------------------------------------------- /test/functor-poly2.sml: -------------------------------------------------------------------------------- 1 | (* functor-poly2.sml *) 2 | 3 | (* Checks higher-order unification with functors. *) 4 | 5 | (* THIS SHOULD PRODUCE A COMPILE TIME ERROR! *) 6 | 7 | functor F(type t) = struct val id = (print "Hello\n"; fn x => x) end 8 | 9 | structure A = F(type t = int) 10 | structure B = F(type t = bool) 11 | 12 | val a = A.id 3 13 | val b = B.id "" 14 | 15 | functor F(type t) = struct val id = (print "Hello\n"; fn x => x) end 16 | 17 | structure A = F(type t = int) : sig val id : int -> int end 18 | structure B = F(type t = bool) : sig val id : string -> string end 19 | -------------------------------------------------------------------------------- /eval/STATE-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML state 5 | * 6 | * Definition, Section 6.3 7 | *) 8 | 9 | signature STATE = 10 | sig 11 | (* Import *) 12 | 13 | type Addr = DynamicObjectsCore.Addr 14 | type ExName = DynamicObjectsCore.ExName 15 | type Val = DynamicObjectsCore.Val 16 | type State = DynamicObjectsCore.State 17 | 18 | 19 | (* Operations *) 20 | 21 | val insertAddr : State * Addr * Val -> State 22 | val insertExName : State * ExName -> State 23 | 24 | val findAddr : State * Addr -> Val option 25 | end; 26 | -------------------------------------------------------------------------------- /basis/OS_FileSys.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library 5 | * 6 | * Note: Incomplete. 7 | *) 8 | 9 | structure OS = 10 | struct 11 | open OS 12 | 13 | structure FileSys : OS_FILE_SYS = 14 | struct 15 | val getDir = use{b = "OS.FileSys.getDir"} : unit -> string 16 | val chDir = use{b = "OS.FileSys.chDir"} : string -> unit 17 | val mkDir = use{b = "OS.FileSys.mkDir"} : string -> unit 18 | val rmDir = use{b = "OS.FileSys.rmDir"} : string -> unit 19 | val isDir = use{b = "OS.FileSys.isDir"} : string -> bool 20 | end 21 | end; 22 | -------------------------------------------------------------------------------- /test/sharing.sml: -------------------------------------------------------------------------------- 1 | (* sharing.sml *) 2 | 3 | (* Checks treatment of sharing constraints. *) 4 | 5 | signature S = 6 | sig 7 | type t 8 | type s = t 9 | sharing type t = s 10 | end; 11 | 12 | signature T = (* from SML/NJ doc *) 13 | sig 14 | type s 15 | structure A : 16 | sig 17 | datatype d = D of s 18 | datatype t = K 19 | end 20 | sharing type s = A.t 21 | end; 22 | 23 | signature U = 24 | sig 25 | datatype t = A | B 26 | datatype u = C 27 | sharing type t = u 28 | end; 29 | 30 | functor F (U : U) = 31 | struct 32 | fun f U.A = 1 33 | | f U.B = 2 34 | | f U.C = 3 35 | end; 36 | -------------------------------------------------------------------------------- /test/valrec.sml: -------------------------------------------------------------------------------- 1 | (* valrec.sml *) 2 | 3 | (* Checks parsing, scoping, typing and dynamic semantics of "val rec". *) 4 | 5 | fun x x = x 6 | val 1 = x 1; 7 | 8 | val a = fn x => x 9 | val a = 1 10 | and rec b = fn x => a(b(c(d(e(f(g x)))))) 11 | and c : 'a -> 'a as d : 'a -> 'a = fn x => x 12 | and rec rec e as f as g = fn x => x 13 | and h : 'b -> 'b : 'b -> 'b = fn x => x; 14 | val 'a rec f = fn x => x; 15 | 16 | val x = 17 | let 18 | val rec LESS = fn x => x (* will raise Bind *) 19 | and NONE as SOME = fn x => x 20 | val SOME = 1 21 | in 22 | raise Fail "should not get here!" 23 | end handle Bind => (); 24 | -------------------------------------------------------------------------------- /test/where.sml: -------------------------------------------------------------------------------- 1 | (* where.sml *) 2 | 3 | (* Checks treatment of type realisations. *) 4 | 5 | signature S = 6 | sig 7 | type t 8 | type s = t 9 | end where type s = int; 10 | 11 | signature T = (* due to Martin Elsman, also see SML/NJ bug 1330 *) 12 | sig 13 | type s 14 | structure U : 15 | sig 16 | type 'a t 17 | type u = (int * real) t 18 | end where type 'a t = s 19 | end where type U.u = int; 20 | 21 | signature U = 22 | sig 23 | datatype t = T 24 | end where type t = bool; 25 | 26 | functor F (U : U) = 27 | struct 28 | fun f U.T = 1 29 | | f true = 2 30 | | f false = 3 31 | end; 32 | -------------------------------------------------------------------------------- /elab/ELAB_PROGRAM-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2013-2025 3 | * 4 | * Standard ML program elaboration 5 | * 6 | * Definition, Section 8 7 | * 8 | * Note: 9 | * Isolates the static semantics aspect of rules 187-189. Not needed for 10 | * executing programs interactively, as defined in Section 8, but useful 11 | * when implementing off-line compilation. 12 | *) 13 | 14 | signature ELAB_PROGRAM = 15 | sig 16 | (* Import types *) 17 | 18 | type Program = SyntaxProgram.Program 19 | type Basis = StaticObjectsModule.Basis 20 | 21 | (* Export *) 22 | 23 | val elabProgram : Basis * Program -> Basis 24 | end; 25 | -------------------------------------------------------------------------------- /main/Makefile.depend.in: -------------------------------------------------------------------------------- 1 | # Main 2 | MAIN-sig.$(EXT) : 3 | Main.$(EXT) : MAIN-sig.$(EXT) Sml.$(EXT) 4 | SML-sig.$(EXT) : 5 | Sml.$(EXT) : SML-sig.$(EXT) ../parse/InitialInfixEnv.$(EXT) ../eval/InitialDynamicBasis.$(EXT) ../elab/InitialStaticBasis.$(EXT) ../lib/StaticLibrary.$(EXT) ../lib/DynamicLibrary.$(EXT) ../parse/Parse.$(EXT) ../parse/SyntacticRestrictionsProgram.$(EXT) ../exec/Program.$(EXT) ../lib/Use.$(EXT) ../infrastructure/Error.$(EXT) ../parse/Infix.$(EXT) ../parse/BindingBasis.$(EXT) ../elab/StaticBasis.$(EXT) ../exec/Basis.$(EXT) ../syntax/PPProgram.$(EXT) ../compile-js/CompileJS.$(EXT) 6 | wrap-$(SYSTEM).$(EXT) : Sml.$(EXT) Main.$(EXT) 7 | -------------------------------------------------------------------------------- /smlnj-lib/ml-yacc-lib.cm: -------------------------------------------------------------------------------- 1 | (* sources file for ML-Yacc library *) 2 | 3 | Library 4 | 5 | signature STREAM 6 | signature LR_TABLE 7 | signature TOKEN 8 | signature LR_PARSER 9 | signature LEXER 10 | signature ARG_LEXER 11 | signature PARSER_DATA 12 | signature PARSER 13 | signature ARG_PARSER 14 | functor Join 15 | functor JoinWithArg 16 | structure LrTable 17 | structure Stream 18 | structure LrParser 19 | 20 | is 21 | 22 | #if defined(NEW_CM) 23 | $/basis.cm 24 | #endif 25 | 26 | (* Need only this for HaMLet... (indentation needed for Makefile hack) *) 27 | base.sml 28 | join.sml 29 | lrtable.sml 30 | stream.sml 31 | parser2.sml 32 | -------------------------------------------------------------------------------- /eval/State.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML state 5 | * 6 | * Definition, Section 6.3 7 | *) 8 | 9 | structure State :> STATE = 10 | struct 11 | (* Import *) 12 | 13 | type Addr = DynamicObjectsCore.Addr 14 | type ExName = DynamicObjectsCore.ExName 15 | type Val = DynamicObjectsCore.Val 16 | type State = DynamicObjectsCore.State 17 | 18 | 19 | (* Operations *) 20 | 21 | fun insertAddr((mem, ens), a, v) = (AddrMap.insert(mem, a, v), ens) 22 | fun insertExName((mem, ens), en) = (mem, ExNameSet.add(ens, en)) 23 | 24 | fun findAddr((mem, ens), a) = AddrMap.find(mem, a) 25 | end; 26 | -------------------------------------------------------------------------------- /syntax/SyntaxProgramFn.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML abstract program syntax 5 | * 6 | * Definition, Section 8 7 | *) 8 | 9 | functor SyntaxProgramFn( 10 | structure Module : 11 | sig 12 | type TopDec 13 | end 14 | 15 | type Program_attr 16 | ) = 17 | struct 18 | (* Import *) 19 | 20 | open Module 21 | 22 | type ('a, 'b) phrase = ('a, 'b) Annotation.phrase 23 | 24 | 25 | (* Programs *) 26 | 27 | datatype Program' = 28 | Program of TopDec * Program option 29 | 30 | 31 | (* Annotated syntax *) 32 | 33 | withtype Program = (Program', Program_attr) phrase 34 | end; 35 | -------------------------------------------------------------------------------- /exec/PPBasis.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML pretty printing of the combined basis 5 | *) 6 | 7 | structure PPBasis : PP_BASIS = 8 | struct 9 | (* Import *) 10 | 11 | type Basis = Basis.Basis 12 | type State = DynamicObjectsCore.State 13 | 14 | open PrettyPrint 15 | 16 | infixr ^^ ^/^ 17 | 18 | 19 | (* Basis *) 20 | 21 | fun ppBasis (s, ((T, F_STAT, G_STAT, E_STAT), (F_DYN, G_DYN, E_DYN))) = 22 | vbox( 23 | PPStaticBasis.ppSigEnv G_STAT ^/^ 24 | PPStaticBasis.ppFunEnv F_STAT ^/^ 25 | PPEnv.ppEnv(s, (E_STAT, E_DYN)) ^/^ 26 | text "" 27 | ) 28 | end; 29 | -------------------------------------------------------------------------------- /syntax/ID-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML identifiers 5 | * 6 | * Definition, Section 2.4 7 | * 8 | * Note: 9 | * This is a generic signature to represent all kinds of identifiers (except 10 | * labels and tyvars). 11 | *) 12 | 13 | signature ID = 14 | sig 15 | (* Type [Section 2.4] *) 16 | 17 | eqtype Id (* [id] *) 18 | 19 | 20 | (* Operations *) 21 | 22 | val invent : unit -> Id 23 | val isInvented : Id -> bool 24 | val fromString : string -> Id 25 | val toString : Id -> string 26 | 27 | val compare : Id * Id -> order 28 | end; 29 | -------------------------------------------------------------------------------- /basis/types.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library top-level types 5 | * 6 | * Note: 7 | * - Vector, array, and substring types are declared with the modules. 8 | *) 9 | 10 | type unit = {} 11 | type int = int 12 | type word = word 13 | type real = real 14 | type char = char 15 | type string = string 16 | type exn = exn 17 | 18 | datatype ref = datatype ref 19 | datatype bool = datatype bool 20 | datatype list = datatype list 21 | 22 | datatype 'a option = NONE | SOME of 'a 23 | datatype order = LESS | EQUAL | GREATER; 24 | -------------------------------------------------------------------------------- /infrastructure/Prop.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2013-2025 3 | * 4 | * Property lists 5 | *) 6 | 7 | structure Prop :> PROP = 8 | struct 9 | type nil = unit 10 | type ('a, 'b) cons = {hd : 'a option ref, tl : 'b option ref} 11 | type 'a prop = 'a option ref 12 | 13 | val none = () 14 | fun new() = {hd = ref NONE, tl = ref NONE} 15 | fun hd{hd, tl} = hd 16 | fun tl{hd, tl = tl as ref NONE} = let val A = new() in tl := SOME A; A end 17 | | tl{hd, tl = tl as ref(SOME A)} = A 18 | 19 | fun has p = Option.isSome(!p) 20 | fun try p = !p 21 | fun get p = Option.valOf(!p) 22 | fun set(p, x) = p := SOME x 23 | end; 24 | -------------------------------------------------------------------------------- /compile-f/F_STATIC-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2013-2025 3 | * 4 | * System F static semantics. 5 | *) 6 | 7 | signature F_STATIC = 8 | sig 9 | type kind = FSyntax.kind 10 | type typ = FSyntax.typ 11 | type value = FSyntax.value 12 | type exp = FSyntax.exp 13 | 14 | type typ_env = kind VarMap.map (* [D] *) 15 | type val_env = typ VarMap.map (* [G] *) 16 | 17 | exception Error of string 18 | 19 | val eqTyp : typ -> typ -> bool 20 | val elabTyp : typ_env * typ -> kind 21 | val elabVal : typ_env * val_env * value -> typ 22 | val elabExp : typ_env * val_env * exp -> typ 23 | end; 24 | -------------------------------------------------------------------------------- /fix/Real-mlkit.sml: -------------------------------------------------------------------------------- 1 | (* MLKit lacks some Real stuff *) 2 | 3 | (* Use the largest available real as 'almost inf'... *) 4 | 5 | structure Real = 6 | struct 7 | open Real 8 | 9 | fun isNormal x = isFinite x andalso !=(abs x, 0.0) 10 | 11 | (* Approximation for ML Kit *) 12 | fun signBit x = Int.<(sign x, 0) 13 | fun copySign(x, y) = if signBit x = signBit y then x else ~x 14 | 15 | fun checkFloat x = if isNan x then raise Div 16 | else if isFinite x then x 17 | else raise Overflow 18 | 19 | (* Approximation for ML Kit *) 20 | fun ?=(x, y) = isNan x orelse isNan y orelse Real.==(x, y) 21 | end 22 | -------------------------------------------------------------------------------- /basis/MATH-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library 5 | *) 6 | 7 | signature MATH = 8 | sig 9 | type real 10 | val pi : real 11 | val e : real 12 | val sqrt : real -> real 13 | val sin : real -> real 14 | val cos : real -> real 15 | val tan : real -> real 16 | val asin : real -> real 17 | val acos : real -> real 18 | val atan : real -> real 19 | val atan2 : real * real -> real 20 | val exp : real -> real 21 | val pow : real * real -> real 22 | val ln : real -> real 23 | val log10 : real -> real 24 | val sinh : real -> real 25 | val cosh : real -> real 26 | val tanh : real -> real 27 | end; 28 | -------------------------------------------------------------------------------- /elab/PP_STATIC_ENV-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML pretty printing of the static environment 5 | *) 6 | 7 | signature PP_STATIC_ENV = 8 | sig 9 | type ValEnv = StaticObjectsCore.ValEnv 10 | type TyEnv = StaticObjectsCore.TyEnv 11 | type Env = StaticObjectsCore.Env 12 | type TyNameSet = StaticObjectsCore.TyNameSet 13 | 14 | val ppEnv : Env -> PrettyPrint.doc 15 | val ppSig : TyNameSet * Env -> PrettyPrint.doc 16 | val ppTyNameSet : TyNameSet -> PrettyPrint.doc 17 | 18 | val ppTyEnv : TyNameSet * TyEnv -> PrettyPrint.doc 19 | val ppExEnv : ValEnv -> PrettyPrint.doc 20 | end; 21 | -------------------------------------------------------------------------------- /eval/InitialDynamicBasis.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML initial dynamic basis 5 | * 6 | * Definition, Appendix D 7 | * 8 | * Notes: see INITIAL_DYNAMIC_ENV-sig.sml 9 | *) 10 | 11 | structure InitialDynamicBasis : INITIAL_DYNAMIC_BASIS = 12 | struct 13 | (* Import *) 14 | 15 | type Basis = DynamicObjectsModule.Basis 16 | type State = DynamicObjectsCore.State 17 | 18 | 19 | (* Environments *) 20 | 21 | val F0 = FunIdMap.empty 22 | val G0 = SigIdMap.empty 23 | val E0 = InitialDynamicEnv.E0 24 | 25 | val B0 = (F0, G0, E0) 26 | 27 | 28 | (* Associated state *) 29 | 30 | val s0 = InitialDynamicEnv.s0 31 | end; 32 | -------------------------------------------------------------------------------- /exec/BASIS-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML combined basis 5 | * 6 | * Definition, Section 8 7 | *) 8 | 9 | signature BASIS = 10 | sig 11 | (* Import *) 12 | 13 | type StaticBasis = StaticObjectsModule.Basis (* [B_STAT] *) 14 | type DynamicBasis = DynamicObjectsModule.Basis (* [B_DYN] *) 15 | 16 | 17 | (* Type [Section 8] *) 18 | 19 | type Basis = StaticBasis * DynamicBasis (* [B] *) 20 | 21 | 22 | (* Operations *) 23 | 24 | val B_STATof : Basis -> StaticBasis 25 | val B_DYNof : Basis -> DynamicBasis 26 | 27 | val oplus : Basis * Basis -> Basis 28 | end; 29 | -------------------------------------------------------------------------------- /parse/InitialInfixEnv.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML initial infix environment 5 | * 6 | * Definition, Appendix C 7 | *) 8 | 9 | structure InitialInfixEnv : INITIAL_INFIX_ENV = 10 | struct 11 | (* Import type *) 12 | 13 | type InfEnv = Infix.InfEnv 14 | 15 | (* Value identifiers *) 16 | 17 | val vidCons = VId.fromString "::" 18 | val vidEqual = VId.fromString "=" 19 | val vidAssign = VId.fromString ":=" 20 | 21 | (* Export *) 22 | 23 | val J0 = 24 | VIdMap.fromList[ 25 | (vidCons, (Infix.RIGHT, 5)), 26 | (vidEqual, (Infix.LEFT, 4)), 27 | (vidAssign, (Infix.LEFT, 3)) 28 | ] 29 | end; 30 | -------------------------------------------------------------------------------- /eval/SVAL-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML special values 5 | * 6 | * Definition, Section 6.2 7 | *) 8 | 9 | signature SVAL = 10 | sig 11 | (* Type [Section 6.2] *) 12 | 13 | datatype SVal = (* [sv] *) 14 | INT of LibrarySVal.IntSVal 15 | | WORD of LibrarySVal.WordSVal 16 | | STRING of LibrarySVal.StringSVal 17 | | CHAR of LibrarySVal.CharSVal 18 | | REAL of LibrarySVal.RealSVal 19 | 20 | (* Operations *) 21 | 22 | val toString : SVal -> string 23 | val equal : SVal * SVal -> bool (* raises Domain *) 24 | val compare : SVal * SVal -> order (* raises Domain *) 25 | end; 26 | -------------------------------------------------------------------------------- /syntax/PP_SYNTAX-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2007-2025 3 | * 4 | * Auxiliaries for printing syntax 5 | *) 6 | 7 | signature PP_SYNTAX = 8 | sig 9 | type outstream = TextIO.outstream 10 | 11 | val ppAtom : outstream * int * string * string -> unit 12 | val ppElem : 13 | outstream * int * string * 'a Annotation.annotation * 14 | (outstream * int -> unit) list -> unit 15 | 16 | val sub : 17 | (outstream * int * 'a -> unit) -> 'a -> outstream * int -> unit 18 | val subs : 19 | (outstream * int * 'a -> unit) -> 'a list -> outstream * int -> unit 20 | val subo : 21 | (outstream * int * 'a -> unit) -> 'a option -> outstream * int -> unit 22 | end; 23 | -------------------------------------------------------------------------------- /eval/VAL-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML values 5 | * 6 | * Definition, Sections 6.2, 6.3, and 6.4 7 | * 8 | * Notes: see DynamicObjectsCore.sml 9 | *) 10 | 11 | signature VAL = 12 | sig 13 | (* Import *) 14 | 15 | type Val = DynamicObjectsCore.Val 16 | type ExVal = DynamicObjectsCore.ExVal 17 | type ExName = DynamicObjectsCore.ExName 18 | 19 | 20 | (* Operations *) 21 | 22 | val equal : Val * Val -> bool 23 | 24 | val exname : ExVal -> ExName 25 | 26 | val fromPair : Val * Val -> Val 27 | val fromList : Val list -> Val 28 | val toPair : Val -> (Val * Val) option 29 | val toList : Val -> Val list option 30 | end; 31 | -------------------------------------------------------------------------------- /syntax/IdFn.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML identifiers 5 | * 6 | * Definition, Section 2.4 7 | * 8 | * Note: 9 | * This is a generic functor to represent all kinds of identifiers (except 10 | * labels and tyvars). 11 | *) 12 | 13 | 14 | functor IdFn() :> ID = 15 | struct 16 | (* Type [Section 2.4] *) 17 | 18 | type Id = string (* [id] *) 19 | 20 | 21 | (* Creation *) 22 | 23 | fun invent() = "_id" ^ Stamp.toString(Stamp.stamp()) 24 | fun isInvented id = String.sub(id, 0) = #"_" 25 | fun fromString s = s 26 | fun toString s = s 27 | 28 | 29 | (* Ordering *) 30 | 31 | val compare = String.compare 32 | end; 33 | -------------------------------------------------------------------------------- /eval/EVAL_PROGRAM-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2013-2025 3 | * 4 | * Standard ML program evaluation 5 | * 6 | * Definition, Section 8 7 | * 8 | * Note: 9 | * - See alse EVAL_CORE-sig.sml 10 | * - Isolates the dynamic semantics aspect of rules 187-189. Not needed for 11 | * executing programs interactively, as defined in Section 8, but useful 12 | * when running programs in batch mode. 13 | *) 14 | 15 | signature EVAL_PROGRAM = 16 | sig 17 | (* Import types *) 18 | 19 | type Program = SyntaxProgram.Program 20 | type Basis = DynamicObjectsModule.Basis 21 | type State = EvalModule.State 22 | 23 | (* Export *) 24 | 25 | val evalProgram : (State ref * Basis) * Program -> Basis 26 | end; 27 | -------------------------------------------------------------------------------- /basis/GENERAL-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library 5 | *) 6 | 7 | signature GENERAL = 8 | sig 9 | type unit = {} 10 | type exn = exn 11 | exception Bind 12 | exception Match 13 | exception Chr 14 | exception Div 15 | exception Domain 16 | exception Fail of string 17 | exception Overflow 18 | exception Size 19 | exception Span 20 | exception Subscript 21 | val exnName : exn -> string 22 | val exnMessage : exn -> string 23 | datatype order = LESS | EQUAL | GREATER 24 | val ! : 'a ref -> 'a 25 | val := : 'a ref * 'a -> unit 26 | val o : ('b -> 'c) * ('a -> 'b) -> 'a -> 'c 27 | val before : 'a * unit -> 'a 28 | val ignore : 'a -> unit 29 | end; 30 | -------------------------------------------------------------------------------- /exec/PROGRAM-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML programs 5 | * 6 | * Definition, Section 8 7 | * 8 | * Note: see EVAL_CORE-sig.sml 9 | *) 10 | 11 | signature PROGRAM = 12 | sig 13 | (* Import *) 14 | 15 | type Program = SyntaxProgram.Program 16 | type StaticBasis = Basis.StaticBasis 17 | type DynamicBasis = Basis.DynamicBasis 18 | type Basis = Basis.Basis 19 | type State = State.State 20 | 21 | 22 | (* Export *) 23 | 24 | val execProgram : bool -> (State ref * Basis) * Program -> Basis 25 | val elabProgram : bool -> StaticBasis * Program -> StaticBasis 26 | val evalProgram : bool -> (State ref * DynamicBasis) * Program -> DynamicBasis 27 | end; 28 | -------------------------------------------------------------------------------- /smlnj-lib/lib-base-sig.sml: -------------------------------------------------------------------------------- 1 | (* lib-base-sig.sml 2 | * 3 | * COPYRIGHT (c) 1993 by AT&T Bell Laboratories. See COPYRIGHT file for details. 4 | *) 5 | 6 | signature LIB_BASE = 7 | sig 8 | 9 | exception Unimplemented of string 10 | (* raised to report unimplemented features *) 11 | exception Impossible of string 12 | (* raised to report internal errors *) 13 | 14 | exception NotFound 15 | (* raised by searching operations *) 16 | 17 | val failure : {module : string, func : string, msg : string} -> 'a 18 | (* raise the exception Fail with a standard format message. *) 19 | 20 | val version : {date : string, system : string, version_id : int list} 21 | val banner : string 22 | 23 | end (* LIB_BASE *) 24 | ; 25 | -------------------------------------------------------------------------------- /basis/OPTION-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library 5 | *) 6 | 7 | signature OPTION = 8 | sig 9 | datatype option = datatype option 10 | exception Option 11 | val getOpt : 'a option * 'a -> 'a 12 | val isSome : 'a option -> bool 13 | val valOf : 'a option -> 'a 14 | val filter : ('a -> bool) -> 'a -> 'a option 15 | val join : 'a option option -> 'a option 16 | val app : ('a -> unit) -> 'a option -> unit 17 | val map : ('a -> 'b) -> 'a option -> 'b option 18 | val mapPartial : ('a -> 'b option) -> 'a option -> 'b option 19 | val compose : ('a -> 'b) * ('c -> 'a option) -> 'c -> 'b option 20 | val composePartial : ('a -> 'b option) * ('c -> 'a option) -> 'c -> 'b option 21 | end; 22 | -------------------------------------------------------------------------------- /smlnj-lib/Makefile.depend.in: -------------------------------------------------------------------------------- 1 | # SML/NJ library 2 | base.$(EXT) : 3 | binary-map-fn.$(EXT) : lib-base.$(EXT) ord-key-sig.$(EXT) ord-map-sig.$(EXT) 4 | binary-set-fn.$(EXT) : lib-base.$(EXT) ord-key-sig.$(EXT) ord-set-sig.$(EXT) 5 | fifo-sig.$(EXT) : 6 | fifo.$(EXT) : fifo-sig.$(EXT) 7 | join.$(EXT) : base.$(EXT) 8 | lib-base-sig.$(EXT) : 9 | lib-base.$(EXT) : lib-base-sig.$(EXT) 10 | lrtable.$(EXT) : base.$(EXT) 11 | ord-key-sig.$(EXT) : 12 | ord-map-sig.$(EXT) : ord-key-sig.$(EXT) 13 | ord-set-sig.$(EXT) : ord-key-sig.$(EXT) 14 | parser1.$(EXT) : base.$(EXT) lrtable.$(EXT) stream.$(EXT) 15 | parser2.$(EXT) : base.$(EXT) lrtable.$(EXT) stream.$(EXT) 16 | queue-sig.$(EXT) : 17 | queue.$(EXT) : queue-sig.$(EXT) fifo.$(EXT) 18 | stream.$(EXT) : base.$(EXT) 19 | -------------------------------------------------------------------------------- /compile-js/JS_TRANSLATE_MODULE-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2013-2025 3 | * 4 | * Translation of module language into JavaScript. 5 | *) 6 | 7 | signature JS_TRANSLATE_MODULE = 8 | sig 9 | (* Import *) 10 | 11 | type TopDec = SyntaxModule.TopDec 12 | 13 | type var = JSSyntax.var 14 | type expr = JSSyntax.expr 15 | type stmt = JSSyntax.stmt 16 | 17 | type Basis = StaticObjectsModule.Basis 18 | 19 | 20 | (* Export *) 21 | 22 | val packBasis : expr option -> Basis -> (string * expr) list 23 | val openBasis : expr -> Basis -> stmt list 24 | val nestTopDec : 25 | Basis * (stmt list -> stmt list) * (stmt list -> stmt list) -> stmt list 26 | 27 | val translateTopDec : TopDec -> stmt list -> stmt list 28 | end; 29 | -------------------------------------------------------------------------------- /infrastructure/PP_MISC-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML miscellaneous pretty printing helpers 5 | *) 6 | 7 | signature PP_MISC = 8 | sig 9 | type doc = PrettyPrint.doc 10 | 11 | val nest : doc -> doc 12 | 13 | val paren : doc -> doc 14 | val brace : doc -> doc 15 | val brack : doc -> doc 16 | val comment : doc -> doc 17 | 18 | val parenAt : int -> int * doc -> doc 19 | 20 | val ppList : ('a -> doc) -> 'a list -> doc 21 | val ppCommaList : ('a -> doc) -> 'a list -> doc 22 | val ppStarList : ('a -> doc) -> 'a list -> doc 23 | val ppSeq : ('a -> doc) -> 'a list -> doc 24 | val ppSeqPrec : (int -> 'a -> doc) -> int -> 'a list -> doc 25 | end; 26 | -------------------------------------------------------------------------------- /elab/FunSig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML functor signatures 5 | * 6 | * Definition, Sections 5.1 and 5.4 7 | *) 8 | 9 | structure FunSig :> FUNSIG = 10 | struct 11 | (* Import types *) 12 | 13 | open StaticObjectsCore 14 | open StaticObjectsModule 15 | 16 | 17 | (* Type variable and type name extraction [Section 4.2] *) 18 | 19 | fun tyvars(T, (E, Sigma)) = 20 | TyVarSet.union(StaticEnv.tyvars E, Sig.tyvars Sigma) 21 | 22 | fun tynames(T, (E, Sigma)) = 23 | TyNameSet.difference( 24 | TyNameSet.union(StaticEnv.tynames E, Sig.tynames Sigma), T) 25 | 26 | fun undetermined(T, (E, Sigma)) = 27 | StampMap.unionWith #2 (StaticEnv.undetermined E, Sig.undetermined Sigma) 28 | end; 29 | -------------------------------------------------------------------------------- /basis/IEEEReal.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library 5 | * 6 | * Note: Incomplete. 7 | *) 8 | 9 | structure IEEEReal :> IEEE_REAL = 10 | struct 11 | exception Unordered 12 | 13 | datatype real_order = LESS | EQUAL | GREATER | UNORDERED 14 | datatype rounding_mode = TO_NEAREST | TO_NEGINF | TO_POSINF | TO_ZERO 15 | datatype float_class = NAN | INF | ZERO | NORMAL | SUBNORMAL 16 | (* 17 | val setRoundingMode : rounding_mode -> unit 18 | val getRoundingMode : unit -> rounding_mode 19 | type decimal_approx = 20 | {kind : float_class, sign : bool, digits : int list, exp : int} 21 | val toString : decimal_approx -> string 22 | val fromString : string -> decimal_approx option 23 | *) 24 | end; 25 | -------------------------------------------------------------------------------- /eval/IntBasis.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML interface basis 5 | * 6 | * Definition, Section 7.2 7 | *) 8 | 9 | structure IntBasis :> INTBASIS = 10 | struct 11 | (* Import types *) 12 | 13 | open IdsCore 14 | open IdsModule 15 | open DynamicObjectsModule 16 | 17 | 18 | (* Injections [Section 7.2] *) 19 | 20 | fun Inter(F, G, E) = (G, Inter.Inter E) 21 | 22 | 23 | (* Modifications [Sections 4.3 and 7.2] *) 24 | 25 | infix plusI 26 | 27 | fun (G, I) plusI I' = (G, Inter.plus(I, I')) 28 | 29 | 30 | (* Application (lookup) [Sections 7.2 and 4.3] *) 31 | 32 | fun findSigId((G, I), sigid) = SigIdMap.find(G, sigid) 33 | 34 | fun findLongTyCon((G, I), longtycon) = Inter.findLongTyCon(I, longtycon) 35 | end; 36 | -------------------------------------------------------------------------------- /compile-js/ID_SET_CORE-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2013-2025 3 | * 4 | * Free and bound identifiers in the core language. 5 | *) 6 | 7 | signature ID_SET_CORE = 8 | sig 9 | type IdSet = {vids : VIdSet.set, strids : StrIdSet.set} 10 | 11 | val boundEnv : StaticObjectsCore.Env -> IdSet 12 | val boundValBind : SyntaxCore.ValBind -> VIdSet.set list 13 | val boundExBind : SyntaxCore.ExBind -> VId.Id list 14 | 15 | val freeDec : SyntaxCore.Dec -> IdSet 16 | val freeValBind : SyntaxCore.ValBind -> IdSet 17 | val freeExBind : SyntaxCore.ExBind -> IdSet 18 | val freeLongStrId : SyntaxCore.longStrId -> IdSet 19 | val freeLongStrIds : SyntaxCore.longStrId list -> IdSet 20 | 21 | val disjoint : IdSet * IdSet -> bool 22 | end; 23 | -------------------------------------------------------------------------------- /eval/DynamicEnv.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML environments of the dynamic semantics of the core 5 | * 6 | * Definition, Sections 6.3 and 6.6 7 | *) 8 | 9 | structure DynamicEnv :> DYNAMIC_ENV = 10 | struct 11 | (* Inheritance *) 12 | 13 | structure GenericEnv = 14 | GenericEnvFn( 15 | open DynamicObjectsCore 16 | type TyStr = ValEnv 17 | fun unEnv(Env E) = E 18 | ) 19 | 20 | open GenericEnv 21 | open DynamicObjectsCore 22 | 23 | 24 | (* Unrolling [Section 6.6] *) 25 | 26 | fun Rec VE = 27 | VIdMap.map 28 | (fn(FcnClosure(match', E', VE'), IdStatus.v) => 29 | (FcnClosure(match', E', VE), IdStatus.v) 30 | | valstr => valstr 31 | ) VE 32 | end; 33 | -------------------------------------------------------------------------------- /lib/Use.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library `use' function 5 | *) 6 | 7 | structure Use : USE = 8 | struct 9 | val inn = ref [] : string list ref 10 | val out = ref [] : string list ref 11 | 12 | fun enqueue name = 13 | if OS.Path.isAbsolute name then 14 | inn := name :: !inn 15 | else 16 | let 17 | val dir = OS.FileSys.getDir() 18 | val path = OS.Path.mkAbsolute{path = name, relativeTo = dir} 19 | in 20 | inn := path :: !inn 21 | end 22 | 23 | fun extract() = 24 | case (!inn, !out) of 25 | ([], []) => NONE 26 | | (_, s::ss) => ( out := ss; SOME s ) 27 | | (ss, []) => ( inn := []; out := List.rev ss; extract() ) 28 | end; 29 | -------------------------------------------------------------------------------- /elab/SIG-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML signatures 5 | * 6 | * Definition, Sections 5.1, 5.3, and 5.6 7 | *) 8 | 9 | signature SIG = 10 | sig 11 | (* Import types *) 12 | 13 | type TyVarSet = StaticObjectsCore.TyVarSet 14 | type TyNameSet = StaticObjectsCore.TyNameSet 15 | type Env = StaticObjectsCore.Env 16 | type Sig = StaticObjectsModule.Sig 17 | type Realisation = Type.Realisation 18 | 19 | 20 | (* Operations *) 21 | 22 | val tyvars : Sig -> TyVarSet 23 | val tynames : Sig -> TyNameSet 24 | val undetermined : Sig -> bool StampMap.map 25 | 26 | val rename : Sig -> Sig 27 | 28 | exception Match 29 | val match : Env * Sig -> Env * Realisation (* raises Match *) 30 | end; 31 | -------------------------------------------------------------------------------- /eval/INTBASIS-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML interface basis 5 | * 6 | * Definition, Section 7.2 7 | *) 8 | 9 | signature INTBASIS = 10 | sig 11 | (* Import types *) 12 | 13 | type longTyCon = IdsCore.longTyCon 14 | type SigId = IdsModule.SigId 15 | 16 | type Int = DynamicObjectsModule.Int 17 | type ValInt = DynamicObjectsModule.ValInt 18 | type Basis = DynamicObjectsModule.Basis 19 | type IntBasis = DynamicObjectsModule.IntBasis 20 | 21 | 22 | (* Operations *) 23 | 24 | val Inter : Basis -> IntBasis 25 | 26 | val plusI : IntBasis * Int -> IntBasis 27 | 28 | val findSigId : IntBasis * SigId -> Int option 29 | val findLongTyCon : IntBasis * longTyCon -> ValInt option 30 | end; 31 | -------------------------------------------------------------------------------- /lib/DYNAMIC_LIBRARY-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library primitives 5 | * 6 | * Definition, Sections 6.2, 6.4 and Appendix D; Standard Basis Specification 7 | *) 8 | 9 | signature DYNAMIC_LIBRARY = 10 | sig 11 | (* Import *) 12 | 13 | type Val = DynamicObjectsCore.Val 14 | type BasVal = DynamicObjectsCore.BasVal 15 | type State = DynamicObjectsCore.State 16 | type Basis = DynamicObjectsModule.Basis 17 | 18 | 19 | (* Value class representation [Section 6.2] *) 20 | 21 | include LIBRARY_SVAL 22 | 23 | (* Initial basis [Appendix D] *) 24 | 25 | val B0 : Basis 26 | val s0 : State 27 | 28 | (* APPLY function [Section 6.4] *) 29 | 30 | exception TypeError of string 31 | val APPLY : BasVal * Val -> Val 32 | end; 33 | -------------------------------------------------------------------------------- /compile-js/JS_TRANSLATE_CORE-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2013-2025 3 | * 4 | * Translation of core language into JavaScript. 5 | *) 6 | 7 | signature JS_TRANSLATE_CORE = 8 | sig 9 | (* Import *) 10 | 11 | type Dec = SyntaxCore.Dec 12 | 13 | type name = JSSyntax.name 14 | type var = JSSyntax.var 15 | type expr = JSSyntax.expr 16 | type stmt = JSSyntax.stmt 17 | 18 | type Env = StaticObjectsCore.Env 19 | 20 | 21 | (* Export *) 22 | 23 | val packVar : expr option -> var -> name * expr 24 | val packEnv : expr option -> Env -> (name * expr) list 25 | val openEnv : expr -> Env -> stmt list 26 | val nestDec : 27 | Env * (stmt list -> stmt list) * (stmt list -> stmt list) -> stmt list 28 | 29 | val translateDec : Dec -> stmt list -> stmt list 30 | end; 31 | -------------------------------------------------------------------------------- /syntax/SCon.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML special constants 5 | * 6 | * Definition, Section 2.2 7 | *) 8 | 9 | structure SCon :> SCON = 10 | struct 11 | (* Types [Section 2.2] *) 12 | 13 | datatype base = DEC | HEX 14 | 15 | datatype SCon = (* [scon] *) 16 | INT of base * string 17 | | WORD of base * string 18 | | STRING of string 19 | | CHAR of string 20 | | REAL of string 21 | 22 | 23 | (* Conversions *) 24 | 25 | fun toString(INT(base, s)) = if base = DEC then s else "0x" ^ s 26 | | toString(WORD(base, s)) = (if base = DEC then "0w" else "0wx") ^ s 27 | | toString(STRING(s)) = "\"" ^ s ^ "\"" 28 | | toString(CHAR(s)) = "#\"" ^ s ^ "\"" 29 | | toString(REAL(s)) = s 30 | end; 31 | -------------------------------------------------------------------------------- /valid/VALID_CORE-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML core elaboration 5 | * 6 | * Definition, Sections 4.10, 4.11, 4.6, 4.7, 2.9 7 | * 8 | * Notes: 9 | * - Elaboration also checks the further restrictions [Section 4.11]. 10 | * - To implement the 3rd restriction in 4.11 elabDec is passed an 11 | * additional argument to recognise being on the toplevel. 12 | *) 13 | 14 | signature VALID_CORE = 15 | sig 16 | (* Import *) 17 | 18 | type Dec = SyntaxCore.Dec 19 | type Ty = SyntaxCore.Ty 20 | 21 | type Type = StaticObjectsCore.Type 22 | type Env = StaticObjectsCore.Env 23 | type Context = StaticObjectsCore.Context 24 | 25 | 26 | (* Export *) 27 | 28 | val validDec : Context * Dec -> Env 29 | val validTy : Context * Ty -> Type 30 | end; 31 | -------------------------------------------------------------------------------- /basis/STRING_CVT-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library 5 | *) 6 | 7 | signature STRING_CVT = 8 | sig 9 | datatype radix = BIN | OCT | DEC | HEX 10 | datatype realfmt 11 | = SCI of int option 12 | | FIX of int option 13 | | GEN of int option 14 | | EXACT 15 | type ('a, 'b) reader = 'b -> ('a * 'b) option 16 | val padLeft : char -> int -> string -> string 17 | val padRight : char -> int -> string -> string 18 | val splitl : (char -> bool) -> (char, 'a) reader ->'a -> (string * 'a) 19 | val takel : (char -> bool) -> (char, 'a) reader ->'a -> string 20 | val dropl : (char -> bool) -> (char, 'a) reader ->'a -> 'a 21 | val skipWS : (char, 'a) reader -> 'a -> 'a 22 | type cs 23 | val scanString : ((char, cs) reader -> ('a, cs) reader) -> string -> 'a option 24 | end; 25 | -------------------------------------------------------------------------------- /lib/STATIC_LIBRARY-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library primitives 5 | * 6 | * Definition, Appendix C and E; Standard Basis Specification 7 | *) 8 | 9 | signature STATIC_LIBRARY = 10 | sig 11 | (* Import *) 12 | 13 | type TyName = StaticObjectsCore.TyName 14 | type OverloadingClass = StaticObjectsCore.OverloadingClass 15 | type Basis = StaticObjectsModule.Basis 16 | 17 | 18 | (* Overloading classes [Section E.1] *) 19 | 20 | val tWord8 : TyName 21 | val tVector : TyName 22 | 23 | val Int : OverloadingClass 24 | val Word : OverloadingClass 25 | val Real : OverloadingClass 26 | val String : OverloadingClass 27 | val Char : OverloadingClass 28 | 29 | (* Initial basis [Appendix C] *) 30 | 31 | val B0 : Basis 32 | end; 33 | -------------------------------------------------------------------------------- /doc/Makefile: -------------------------------------------------------------------------------- 1 | BIB_LTX = '\\bibliography\{' 2 | CITE_LTX = 'LaTeX Warning: Citation' 3 | WARN_LTX = 'Rerun to get cross-references right|There were undefined references|There were undefined citations' 4 | 5 | .PRECIOUS: Manual.dvi Manual.ps Mistakes.dvi Mistakes.ps 6 | 7 | all: Manual.pdf Mistakes.pdf 8 | 9 | %.pdf: %.ps 10 | ps2pdf $< $@ 11 | 12 | %.ps: %.dvi 13 | dvips $< -o $@ 14 | 15 | %.dvi: %.tex 16 | latex $< 17 | if egrep -s $(BIB_LTX) $<; then \ 18 | bibtex $(basename $<) || { rm -f $@; exit 1; }; \ 19 | latex $<; \ 20 | if egrep -s $(CITE_LTX) $*.log; then \ 21 | bibtex $(basename $<) || { rm -f $@; exit 1; } \ 22 | fi; \ 23 | latex $<; \ 24 | fi 25 | while egrep -s $(WARN_LTX) $*.log; do \ 26 | latex $< || { rm -f $@; exit 1; } \ 27 | done 28 | 29 | clean: 30 | rm -f *.aux *.bbl *.blg *.dvi *.log *.ps *.out 31 | -------------------------------------------------------------------------------- /elab/ELAB_CORE-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML core elaboration 5 | * 6 | * Definition, Sections 4.10, 4.11, 4.6, 4.7, 2.9 7 | * 8 | * Notes: 9 | * - Elaboration also checks the further restrictions [Section 4.11]. 10 | * - To implement the 3rd restriction in 4.11 elabDec is passed an 11 | * additional argument to indicate the toplevel. 12 | *) 13 | 14 | signature ELAB_CORE = 15 | sig 16 | (* Import *) 17 | 18 | type Dec = SyntaxCore.Dec 19 | type Ty = SyntaxCore.Ty 20 | 21 | type Type = StaticObjectsCore.Type 22 | type Env = StaticObjectsCore.Env 23 | type Context = StaticObjectsCore.Context 24 | 25 | 26 | (* Export *) 27 | 28 | datatype level = TOP | INNER 29 | 30 | val elabDec : level -> Context * Dec -> Env 31 | val elabTy : Context * Ty -> Type 32 | end; 33 | -------------------------------------------------------------------------------- /exec/Basis.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML combined basis 5 | * 6 | * Definition, Section 8 7 | *) 8 | 9 | structure Basis :> BASIS = 10 | struct 11 | (* Import *) 12 | 13 | type StaticBasis = StaticObjectsModule.Basis (* [B_STAT] *) 14 | type DynamicBasis = DynamicObjectsModule.Basis (* [B_DYN] *) 15 | 16 | 17 | (* Type [Section 8] *) 18 | 19 | type Basis = StaticBasis * DynamicBasis (* [B] *) 20 | 21 | 22 | (* Projections *) 23 | 24 | fun B_STATof(B_STAT, B_DYN) = B_STAT 25 | fun B_DYNof(B_STAT, B_DYN) = B_DYN 26 | 27 | 28 | (* Modification [Section 4.3] *) 29 | 30 | infix oplus 31 | 32 | fun (B_STAT, B_DYN) oplus (B_STAT', B_DYN') = 33 | (StaticBasis.plus(B_STAT, B_STAT'), DynamicBasis.plus(B_DYN, B_DYN')) 34 | end; 35 | -------------------------------------------------------------------------------- /compile-js/ID_SET_MODULE-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2013-2025 3 | * 4 | * Free and bound identifiers in the module language. 5 | *) 6 | 7 | signature ID_SET_MODULE = 8 | sig 9 | type IdSet = {vids : VIdSet.set, strids : StrIdSet.set, funids : FunIdSet.set} 10 | 11 | val boundEnv : StaticObjectsModule.Env -> IdSet 12 | val boundBasis : StaticObjectsModule.Basis -> IdSet 13 | val boundStrBind : SyntaxModule.StrBind -> StrId.Id list 14 | val boundFunBind : SyntaxModule.FunBind -> FunId.Id list 15 | 16 | val freeStrDec : SyntaxModule.StrDec -> IdSet 17 | val freeFunDec : SyntaxModule.FunDec -> IdSet 18 | val freeTopDec : SyntaxModule.TopDec -> IdSet 19 | val freeStrBind : SyntaxModule.StrBind -> IdSet 20 | val freeFunBind : SyntaxModule.FunBind -> IdSet 21 | 22 | val disjoint : IdSet * IdSet -> bool 23 | end; 24 | -------------------------------------------------------------------------------- /parse/BindingObjectsModule.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML objects for binding analysis of modules 5 | * 6 | * Definition, Sections 2.9 and 3.5 7 | * 8 | * Notes: 9 | * - The "syntactic restrictions" defined in the Definition are not purely 10 | * syntactic. E.g. the restriction that valbinds may not bind the same vid 11 | * twice [2nd bullet] cannot be checked without proper binding analysis 12 | * that computes identifier status. 13 | *) 14 | 15 | structure BindingObjectsModule = 16 | struct 17 | (* Import *) 18 | 19 | type 'a SigIdMap = 'a IdsModule.SigIdMap 20 | type 'a FunIdMap = 'a IdsModule.FunIdMap 21 | 22 | type Env = BindingObjectsCore.Env 23 | 24 | 25 | (* Types *) 26 | 27 | type SigEnv = Env SigIdMap 28 | type FunEnv = Env FunIdMap 29 | type Basis = FunEnv * SigEnv * Env 30 | end; 31 | -------------------------------------------------------------------------------- /eval/ExName.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML exception names and sets thereof 5 | * 6 | * Definition, Sections 6.2 and 6.3 7 | *) 8 | 9 | 10 | structure ExName :> EXNAME = 11 | struct 12 | (* Import *) 13 | 14 | type VId = VId.Id 15 | type stamp = Stamp.stamp 16 | 17 | 18 | (* Type [Section 6.2] *) 19 | 20 | type ExName = {vid : VId, stamp : stamp} (* [en] *) 21 | 22 | 23 | (* Creation *) 24 | 25 | fun exname vid = {vid = vid, stamp = Stamp.stamp()} 26 | 27 | 28 | (* Conversion *) 29 | 30 | fun toString{vid, stamp} = VId.toString vid 31 | 32 | 33 | (* Ordering *) 34 | 35 | fun compare(en1 : ExName, en2 : ExName) = 36 | Stamp.compare(#stamp en1, #stamp en2) 37 | end 38 | 39 | structure ExNameSet = 40 | FinSetFn(type ord_key = ExName.ExName; val compare = ExName.compare); 41 | -------------------------------------------------------------------------------- /basis/Text.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2002-2025 3 | * 4 | * Standard ML Basis Library 5 | *) 6 | 7 | structure Text :> TEXT 8 | where type Char.char = Char.char 9 | (* redundant and illegal 10 | where type String.string = String.string 11 | where type Substring.substring = Substring.substring 12 | *) 13 | where type CharVector.vector = CharVector.vector 14 | where type CharArray.array = CharArray.array 15 | where type CharVectorSlice.slice = CharVectorSlice.slice 16 | where type CharArraySlice.slice = CharArraySlice.slice = 17 | struct 18 | structure Char = Char 19 | structure String = String 20 | structure Substring = Substring 21 | structure CharVector = CharVector 22 | structure CharArray = CharArray 23 | structure CharVectorSlice = CharVectorSlice 24 | structure CharArraySlice = CharArraySlice 25 | end; 26 | -------------------------------------------------------------------------------- /smlnj-lib/fifo-sig.sml: -------------------------------------------------------------------------------- 1 | (* fifo-sig.sml 2 | * 3 | * COPYRIGHT (c) 1993 by AT&T Bell Laboratories. See COPYRIGHT file for details. 4 | * 5 | * Applicative fifos 6 | * 7 | *) 8 | 9 | signature FIFO = 10 | sig 11 | type 'a fifo 12 | 13 | exception Dequeue 14 | 15 | val empty : 'a fifo 16 | val isEmpty : 'a fifo -> bool 17 | val enqueue : 'a fifo * 'a -> 'a fifo 18 | val dequeue : 'a fifo -> 'a fifo * 'a 19 | val delete : ('a fifo * ('a -> bool)) -> 'a fifo 20 | val head : 'a fifo -> 'a 21 | val peek : 'a fifo -> 'a option 22 | val length : 'a fifo -> int 23 | val contents : 'a fifo -> 'a list 24 | val app : ('a -> unit) -> 'a fifo -> unit 25 | val map : ('a -> 'b) -> 'a fifo -> 'b fifo 26 | val foldl : ('a * 'b -> 'b) -> 'b -> 'a fifo -> 'b 27 | val foldr : ('a * 'b -> 'b) -> 'b -> 'a fifo -> 'b 28 | 29 | end (* FIFO *) 30 | -------------------------------------------------------------------------------- /eval/BasVal.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML basic values 5 | * 6 | * Definition, Section 6.4 7 | *) 8 | 9 | structure BasVal :> BASVAL = 10 | struct 11 | (* Import *) 12 | 13 | open DynamicObjectsCore 14 | 15 | 16 | (* Conversions *) 17 | 18 | fun toString b = b 19 | 20 | 21 | (* Application of basic values *) 22 | 23 | exception TypeError = DynamicLibrary.TypeError 24 | 25 | fun fromBool b = VId(VId.fromString(if b then "true" else "false")) 26 | 27 | fun APPLY("=", v) = 28 | (case Val.toPair v of 29 | SOME vv => 30 | ( fromBool(Val.equal vv) handle Domain => 31 | raise TypeError "equality type expected" 32 | ) 33 | | NONE => 34 | raise TypeError "pair expected" 35 | ) 36 | | APPLY(b, v) = 37 | DynamicLibrary.APPLY(b, v) 38 | end; 39 | -------------------------------------------------------------------------------- /test/fun-infix.sml: -------------------------------------------------------------------------------- 1 | (* fun-infix.sml *) 2 | 3 | (* Checks for parsing of infixed fun declarations *) 4 | 5 | datatype t = C of int 6 | datatype u = * of int * int 7 | datatype v = / of t * t 8 | 9 | fun x + y : int = x 10 | fun (x) + (y) : int = x 11 | fun (x + y) : int = x 12 | fun ((x) + (y)) : int = x 13 | fun ((x) + (y)) z : int = x 14 | fun ((x) + (y)) (z) a b : int = x 15 | fun (C x) + (C y) : int = x 16 | fun ((C x) + (C y)) : int = x 17 | fun (((C(x))) + ((C(y)))) a (z : int) b : int = x 18 | fun (x*y) + (a*b) : int = x 19 | fun ((x*y) + (a*b)) : int = x 20 | fun ((x*y) + (a*b)) z : int = x 21 | fun ((C x/C y) + (C a/C b)) : int = x 22 | fun ((C x/C y) + (C a/C b)) z : int = x 23 | 24 | (* Note that neither of the following has to be accepted: 25 | 26 | fun C x + C y : int = x 27 | fun C(x) + C(y) : int = x 28 | fun (C x + C y) : int = x 29 | fun (C(x) + C(y)) : int = x 30 | 31 | *) 32 | -------------------------------------------------------------------------------- /infrastructure/FIN_MAP-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML finite maps 5 | * 6 | * Definition, Section 4.2 7 | * 8 | * Note: This signature just extends the one available in the SML/NJ lib. 9 | *) 10 | 11 | signature FIN_MAP = 12 | sig 13 | include ORD_MAP 14 | 15 | exception NotFound 16 | exception Duplicate 17 | 18 | val fromList : (Key.ord_key * 'a) list -> 'a map 19 | 20 | val extend : 'a map * (Key.ord_key * 'a) -> 'a map 21 | val delete : 'a map * Key.ord_key -> 'a map 22 | val difference : 'a map * 'a map -> 'a map 23 | 24 | val all : ('a -> bool) -> 'a map -> bool 25 | val exists : ('a -> bool) -> 'a map -> bool 26 | val alli : (Key.ord_key * 'a -> bool) -> 'a map -> bool 27 | val existsi : (Key.ord_key * 'a -> bool) -> 'a map -> bool 28 | val disjoint : 'a map * 'a map -> bool 29 | end; 30 | -------------------------------------------------------------------------------- /parse/SyntacticRestrictionsProgram.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML syntactic restrictions for programs 5 | *) 6 | 7 | structure SyntacticRestrictionsProgram : SYNTACTIC_RESTRICTIONS_PROGRAM = 8 | struct 9 | (* Import *) 10 | 11 | open SyntaxProgram 12 | open AnnotationProgram 13 | 14 | type Basis = SyntacticRestrictionsModule.Basis 15 | 16 | 17 | (* Helpers *) 18 | 19 | val plus = BindingBasis.plus 20 | 21 | infix plus 22 | 23 | fun ?check(B, NONE) default = default 24 | | ?check(B, SOME phrase) default = check(B, phrase) 25 | 26 | 27 | (* Operation *) 28 | 29 | fun checkProgram(B, Program(topdec, program_opt)@@A) = 30 | let 31 | val B1 = SyntacticRestrictionsModule.checkTopDec(B, topdec) 32 | val B' = B plus B1 33 | in 34 | ?checkProgram(B', program_opt) B' 35 | end 36 | end; 37 | -------------------------------------------------------------------------------- /basis/TEXT-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2002-2025 3 | * 4 | * Standard ML Basis Library 5 | *) 6 | 7 | signature TEXT = 8 | sig 9 | structure Char : CHAR 10 | structure String : STRING 11 | structure Substring : SUBSTRING 12 | structure CharVector : MONO_VECTOR 13 | structure CharArray : MONO_ARRAY 14 | structure CharVectorSlice : MONO_VECTOR_SLICE 15 | structure CharArraySlice : MONO_ARRAY_SLICE 16 | sharing type Char.char = String.char = Substring.char 17 | = CharVector.elem = CharArray.elem = CharVectorSlice.elem 18 | = CharArraySlice.elem 19 | sharing type Char.string = String.string = Substring.string 20 | = CharVector.vector = CharArray.vector 21 | = CharVectorSlice.vector = CharArraySlice.vector 22 | sharing type CharArray.array = CharArraySlice.array 23 | sharing type CharVectorSlice.slice = CharArraySlice.vector_slice 24 | end; 25 | -------------------------------------------------------------------------------- /syntax/TYVAR-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML type variables 5 | * 6 | * Definition, Sections 2.4 and 4.1 7 | *) 8 | 9 | signature TYVAR = 10 | sig 11 | (* Import types *) 12 | 13 | type OverloadingClass = OverloadingClass.OverloadingClass 14 | 15 | 16 | (* Type [Sections 2.4 and 4.1]*) 17 | 18 | eqtype TyVar (* [alpha] or [tyvar] *) 19 | 20 | 21 | (* Operations *) 22 | 23 | val invent : bool -> TyVar 24 | val fromInt : bool -> int -> TyVar 25 | val fromString : string -> TyVar 26 | val fromOverloadingClass : string * OverloadingClass -> TyVar 27 | val toString : TyVar -> string 28 | 29 | val admitsEquality : TyVar -> bool 30 | val overloadingClass : TyVar -> OverloadingClass option 31 | 32 | val compare : TyVar * TyVar -> order 33 | end; 34 | -------------------------------------------------------------------------------- /elab/StaticObjectsModule.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML objects of the static semantics of modules 5 | * 6 | * Definition, Section 5.1 7 | *) 8 | 9 | structure StaticObjectsModule = 10 | struct 11 | (* Import *) 12 | 13 | type 'a SigIdMap = 'a IdsModule.SigIdMap 14 | type 'a FunIdMap = 'a IdsModule.FunIdMap 15 | 16 | type Env = StaticObjectsCore.Env 17 | type TyNameSet = StaticObjectsCore.TyNameSet 18 | 19 | 20 | (* Compound objects [Section 5.1] *) 21 | 22 | type Sig = TyNameSet * Env (* [Sigma] *) 23 | type FunSig = TyNameSet * (Env * Sig) (* [Phi] *) 24 | 25 | type SigEnv = Sig SigIdMap (* [G] *) 26 | type FunEnv = FunSig FunIdMap (* [F] *) 27 | type Basis = TyNameSet * FunEnv * SigEnv * Env (* [B] *) 28 | end; 29 | -------------------------------------------------------------------------------- /syntax/IdsModule.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML identifiers for modules, and sets and maps thereof 5 | * 6 | * Definition, Section 3.2 7 | *) 8 | 9 | structure SigId = IdFn() 10 | structure FunId = IdFn() 11 | 12 | structure SigIdSet = 13 | FinSetFn(type ord_key = SigId.Id; val compare = SigId.compare) 14 | structure FunIdSet = 15 | FinSetFn(type ord_key = FunId.Id; val compare = FunId.compare) 16 | 17 | structure SigIdMap = 18 | FinMapFn(type ord_key = SigId.Id; val compare = SigId.compare) 19 | structure FunIdMap = 20 | FinMapFn(type ord_key = FunId.Id; val compare = FunId.compare) 21 | 22 | 23 | structure IdsModule = 24 | struct 25 | type SigId = SigId.Id 26 | type FunId = FunId.Id 27 | 28 | type SigIdSet = SigIdSet.set 29 | type FunIdSet = FunIdSet.set 30 | 31 | type 'a SigIdMap = 'a SigIdMap.map 32 | type 'a FunIdMap = 'a FunIdMap.map 33 | end; 34 | -------------------------------------------------------------------------------- /basis/CharArray.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library 5 | * 6 | * Note: 7 | * - Array type kept transparent to allow trivial implementation 8 | * of CharArraySlice. 9 | *) 10 | 11 | structure CharArray : MONO_ARRAY 12 | where type vector = CharVector.vector 13 | where type elem = char = 14 | struct 15 | open Array 16 | 17 | type array = char array 18 | type elem = char 19 | type vector = CharVector.vector 20 | 21 | fun vector arr = CharVector.tabulate(length arr, fn i => sub(arr, i)) 22 | 23 | fun copyVec{src, dst, di} = 24 | if di < 0 orelse length dst < di + CharVector.length src 25 | then raise Subscript 26 | else copyVec'(src, dst, di, 0) 27 | and copyVec'(src, dst, di, i) = 28 | if i = CharVector.length src then () else 29 | ( update(dst, di + i, CharVector.sub(src, i)); 30 | copyVec'(src, dst, di, i + 1) ) 31 | end; 32 | -------------------------------------------------------------------------------- /eval/EVAL_CORE-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML core evaluation 5 | * 6 | * Definition, Section 6.7 7 | * 8 | * Notes: 9 | * - State is passed as reference and modified via side effects. This way 10 | * expanding out of the state and exception convention in the inference 11 | * rules can be avoided (which would really be a pain). Note that the state 12 | * therefore never is returned. 13 | * - Doing so, we can model the exception convention using exceptions. 14 | * - Since exception names are generated by stamps we do not really need the 15 | * exception name set. We maintain it anyway. 16 | *) 17 | 18 | signature EVAL_CORE = 19 | sig 20 | (* Import types *) 21 | 22 | type Dec = SyntaxCore.Dec 23 | type Env = DynamicObjectsCore.Env 24 | type State = DynamicObjectsCore.State 25 | 26 | (* Export *) 27 | 28 | val evalDec : (State ref * Env) * Dec -> Env 29 | end; 30 | -------------------------------------------------------------------------------- /basis/General.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library 5 | *) 6 | 7 | structure General :> GENERAL = 8 | struct 9 | type unit = {} 10 | type exn = exn 11 | 12 | exception Bind = Bind 13 | exception Chr = Chr 14 | exception Div = Div 15 | exception Domain = Domain 16 | exception Fail = Fail 17 | exception Match = Match 18 | exception Overflow = Overflow 19 | exception Size = Size 20 | exception Span = Span 21 | exception Subscript = Subscript 22 | 23 | val exnName = use{b = "General.exnName"} : exn -> string 24 | val exnMessage = exnName 25 | 26 | datatype order = LESS | EQUAL | GREATER 27 | 28 | fun !(ref v) = v 29 | val op:= = op:= 30 | 31 | fun (f o g) a = f(g a) 32 | fun a before b = a 33 | fun ignore a = () 34 | end 35 | 36 | open General; 37 | -------------------------------------------------------------------------------- /eval/INITIAL_DYNAMIC_ENV-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML core view of the initial dynamic basis 5 | * 6 | * Definition, Appendix D and Section 6.5 7 | * 8 | * Note: 9 | * The Definition does not specify what the initial state has to contain. 10 | * This is a bug as it must at least contain the exception names Match 11 | * and Bind. We put the state associated with the initial environment in 12 | * here, too. 13 | *) 14 | 15 | signature INITIAL_DYNAMIC_ENV = 16 | sig 17 | (* Import *) 18 | 19 | type Env = DynamicObjectsCore.Env 20 | type ExName = DynamicObjectsCore.ExName 21 | type State = DynamicObjectsCore.State 22 | 23 | 24 | (* Basic exception names [Section 6.5] *) 25 | 26 | val enMatch : ExName 27 | val enBind : ExName 28 | 29 | (* Initial environment [Appendix D] *) 30 | 31 | val E0 : Env 32 | 33 | (* Associated state *) 34 | 35 | val s0 : State 36 | end; 37 | -------------------------------------------------------------------------------- /test/redundant.sml: -------------------------------------------------------------------------------- 1 | (* redundant.sml *) 2 | 3 | (* Checks detection of redundant matches involving exception constructors. *) 4 | 5 | (* HaMLet does not handle it. *) 6 | 7 | exception E 8 | exception F = E 9 | 10 | fun f E = 1 11 | | f F = 2 12 | | f _ = 0; 13 | 14 | signature S = sig exception E end 15 | 16 | structure X1 = struct exception E = E end 17 | structure X2 : S = struct exception E = E end 18 | structure X3 :> S = struct exception E = E end 19 | 20 | fun f() = (raise E) handle E => () | X1.E => () 21 | fun f() = (raise E) handle E => () | X2.E => () 22 | fun f() = (raise E) handle E => () | X3.E => () 23 | 24 | functor F(exception E exception F) = 25 | struct 26 | fun f() = (raise E) handle E => () | F => () 27 | end 28 | 29 | structure X = F(exception E exception F = E) (* should warn *) 30 | structure X = F(exception E exception F = E) (* should warn *) 31 | structure X = F(exception E exception F); (* should not warn *) 32 | -------------------------------------------------------------------------------- /basis/Option.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library 5 | *) 6 | 7 | structure Option :> OPTION = 8 | struct 9 | datatype option = datatype option 10 | 11 | exception Option 12 | 13 | fun getOpt(SOME v, a) = v 14 | | getOpt(NONE, a) = a 15 | 16 | fun isSome(SOME v) = true 17 | | isSome NONE = false 18 | 19 | fun valOf(SOME v) = v 20 | | valOf NONE = raise Option 21 | 22 | fun filter f a = if f a then SOME a else NONE 23 | 24 | fun join NONE = NONE 25 | | join(SOME v) = v 26 | 27 | fun app f NONE = () 28 | | app f (SOME v) = f v 29 | 30 | fun map f NONE = NONE 31 | | map f (SOME v) = SOME(f v) 32 | 33 | fun mapPartial f = join o (map f) 34 | fun compose (f, g) = (map f) o g 35 | fun composePartial (f, g) = (mapPartial f) o g 36 | end; 37 | -------------------------------------------------------------------------------- /syntax/Lab.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML label identifiers and maps thereof 5 | * 6 | * Definition, Sections 2.4 and 4.2 7 | *) 8 | 9 | structure Lab :> LAB = 10 | struct 11 | (* Type [Section 2.4] *) 12 | 13 | type Lab = string (* [lab] *) 14 | 15 | 16 | (* Conversions *) 17 | 18 | fun toString s = s 19 | fun fromString s = s 20 | fun fromInt i = Int.toString i 21 | fun toInt lab = Int.fromString lab 22 | 23 | 24 | (* Ordering *) 25 | 26 | fun compare(lab1, lab2) = 27 | (case (Int.fromString lab1, Int.fromString lab2) of 28 | (SOME i1, SOME i2) => Int.compare(i1, i2) 29 | | _ => String.compare(lab1, lab2) 30 | ) handle Overflow => String.compare(lab1, lab2) 31 | end 32 | 33 | structure LabSet = FinSetFn(type ord_key = Lab.Lab; val compare = Lab.compare) 34 | structure LabMap = FinMapFn(type ord_key = Lab.Lab; val compare = Lab.compare); 35 | -------------------------------------------------------------------------------- /eval/EvalProgram.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2013-2025 3 | * 4 | * Standard ML program evaluation 5 | * 6 | * Definition, Section 8 7 | * 8 | * Notes: see EVAL_PROGRAM-sig.sml 9 | *) 10 | 11 | structure EvalProgram : EVAL_PROGRAM = 12 | struct 13 | (* Import *) 14 | 15 | open SyntaxProgram 16 | open AnnotationProgram 17 | open DynamicObjectsModule 18 | open Error 19 | 20 | type State = EvalCore.State 21 | 22 | 23 | (* Helpers for basis modification *) 24 | 25 | val plus = DynamicBasis.plus 26 | 27 | infix plus 28 | 29 | fun ?eval(B, NONE) default = default 30 | | ?eval(B, SOME phrase) default = eval(B, phrase) 31 | 32 | 33 | (* Programs *) 34 | 35 | fun evalProgram((s, B), Program(topdec, program_opt)@@A) = 36 | let 37 | val B1 = EvalModule.evalTopDec((s, B), topdec) 38 | val B' = B plus B1 39 | val B'' = ?evalProgram((s, B'), program_opt) B' 40 | in 41 | B'' 42 | end 43 | end; 44 | -------------------------------------------------------------------------------- /basis/Byte.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2002-2025 3 | * 4 | * Standard ML Basis Library 5 | *) 6 | 7 | structure Byte :> BYTE = 8 | struct 9 | fun byteToChar i = Char.chr(Word8.toInt i) 10 | fun charToByte c = Word8.fromInt(Char.ord c) 11 | 12 | fun stringToBytes s = 13 | Word8Vector.tabulate(CharVector.length s, 14 | fn i => charToByte(CharVector.sub(s, i))) 15 | 16 | fun bytesToString v = 17 | CharVector.tabulate(Word8Vector.length v, 18 | fn i => byteToChar(Word8Vector.sub(v, i))) 19 | 20 | fun unpackStringVec sl = 21 | CharVector.tabulate(Word8VectorSlice.length sl, 22 | fn i => byteToChar(Word8VectorSlice.sub(sl, i))) 23 | 24 | fun unpackString sl = 25 | CharVector.tabulate(Word8ArraySlice.length sl, 26 | fn i => byteToChar(Word8ArraySlice.sub(sl, i))) 27 | 28 | fun packString(arr, i, ss) = 29 | Word8Array.copyVec{ 30 | src = stringToBytes(Substring.string ss), dst = arr, di = i} 31 | end; 32 | -------------------------------------------------------------------------------- /compile-js/CompileJS.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2013-2025 3 | * 4 | * Translation of programs into JavaScript. 5 | *) 6 | 7 | structure CompileJS : COMPILE_JS = 8 | struct 9 | (* Import *) 10 | 11 | type Program = SyntaxProgram.Program 12 | type StaticBasis = StaticObjectsModule.Basis 13 | 14 | 15 | (* Helpers for output *) 16 | 17 | val width = 79 18 | 19 | fun printStmts out stmts = 20 | let 21 | val docs = List.map PPJS.ppStmt stmts 22 | val doc = List.foldr PrettyPrint.^/^ (PrettyPrint.text "") docs 23 | in 24 | PrettyPrint.output(out, PrettyPrint.vbox doc, width); 25 | TextIO.flushOut out 26 | end 27 | 28 | 29 | (* Export *) 30 | 31 | fun compileProgram out (B, program) = 32 | let 33 | val B' = ElabProgram.elabProgram(B, program) 34 | val stmts = JSTranslateProgram.translateProgram(B, program) 35 | in 36 | printStmts out stmts; 37 | B' 38 | end 39 | end; 40 | -------------------------------------------------------------------------------- /smlnj-lib/stream.sml: -------------------------------------------------------------------------------- 1 | (* ML-Yacc Parser Generator (c) 1989 Andrew W. Appel, David R. Tarditi 2 | * 3 | * $Log$ 4 | * Revision 1.1 2000/11/24 13:32:28 rossberg 5 | * *** empty log message *** 6 | * 7 | * Revision 1.2 1997/08/26 19:18:55 jhr 8 | * Replaced used of "abstraction" with ":>". 9 | * 10 | # Revision 1.1.1.1 1997/01/14 01:38:04 george 11 | # Version 109.24 12 | # 13 | * Revision 1.1.1.1 1996/01/31 16:01:43 george 14 | * Version 109 15 | * 16 | *) 17 | 18 | (* Stream: a structure implementing a lazy stream. The signature STREAM 19 | is found in base.sig *) 20 | 21 | structure Stream :> STREAM = 22 | struct 23 | datatype 'a str = EVAL of 'a * 'a str ref | UNEVAL of (unit->'a) 24 | 25 | type 'a stream = 'a str ref 26 | 27 | fun get s = 28 | case !s of EVAL t => t 29 | | UNEVAL f => 30 | let val t = (f(), ref(UNEVAL f)) in s := EVAL t; t end 31 | 32 | fun streamify f = ref(UNEVAL f) 33 | fun cons(a,s) = ref(EVAL(a,s)) 34 | 35 | end; 36 | -------------------------------------------------------------------------------- /syntax/LONGID-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML long identifiers 5 | * 6 | * Definition, Section 2.4 7 | * 8 | * Note: 9 | * This is a generic signature to represent all kinds of long identifiers. 10 | *) 11 | 12 | signature LONGID = 13 | sig 14 | (* Import *) 15 | 16 | structure Id : ID 17 | structure StrId : ID 18 | 19 | type Id = Id.Id 20 | type StrId = StrId.Id 21 | 22 | 23 | (* Type [Section 2.4] *) 24 | 25 | eqtype longId (* [longid] *) 26 | 27 | 28 | (* Operations *) 29 | 30 | val invent : unit -> longId 31 | val fromId : Id -> longId 32 | val toId : longId -> Id 33 | val toString : longId -> string 34 | 35 | val strengthen : StrId * longId -> longId 36 | val implode : StrId list * Id -> longId 37 | val explode : longId -> StrId list * Id 38 | 39 | val isShort : longId -> bool 40 | 41 | val compare : longId * longId -> order 42 | end; 43 | -------------------------------------------------------------------------------- /fix/Real-mosml.sml: -------------------------------------------------------------------------------- 1 | (* Moscow ML lacks some Real stuff and infinity and / raises Div exception *) 2 | 3 | (* Use the largest available real as 'almost inf'... *) 4 | 5 | structure Real = 6 | struct 7 | open Real 8 | 9 | (* Approximation for Moscow ML *) 10 | fun x/y = Real./(x, y) handle Div => 11 | if x > 0.0 12 | then 8.98846567431e307 13 | else ~8.98846567431e307 14 | 15 | fun isNan x = !=(x, x) 16 | fun isFinite x = abs x <> 1.0/0.0 17 | fun isNormal x = isFinite x andalso abs x <> 0.0 18 | 19 | fun signBit x = Int.<(sign x, 0) orelse x = ~0.0 20 | fun copySign(x, y) = if signBit x = signBit y then x else ~x 21 | 22 | fun checkFloat x = if isNan x then raise Div 23 | else if isFinite x then x 24 | else raise Overflow 25 | 26 | fun toString x = (if signBit x then "~" else "") ^ Real.toString(abs x) 27 | end 28 | 29 | val op/ = Real./ 30 | -------------------------------------------------------------------------------- /elab/ElabProgram.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2013-2025 3 | * 4 | * Standard ML program elaboration 5 | * 6 | * Definition, Section 8 7 | * 8 | * Note: see ELAB_PROGRAM-sig.sml 9 | *) 10 | 11 | structure ElabProgram : ELAB_PROGRAM = 12 | struct 13 | (* Import types *) 14 | 15 | open SyntaxProgram 16 | open AnnotationProgram 17 | open StaticObjectsModule 18 | open Error 19 | 20 | 21 | (* Helpers for basis modification and side conditions *) 22 | 23 | val plus = StaticBasis.plus 24 | 25 | infix plus 26 | infix --> 27 | 28 | fun ?elab(B, NONE) default = default 29 | | ?elab(B, SOME phrase) default = elab(B, phrase) 30 | 31 | 32 | (* Programs *) 33 | 34 | fun elabProgram(B, Program(topdec, program_opt)@@A) = 35 | (* [cf. Rule 188 or 189] *) 36 | let 37 | val B1 = ElabModule.elabTopDec(B, topdec) 38 | val B' = B plus B1 39 | val B'' = ?elabProgram(B', program_opt) B' 40 | in 41 | B'' 42 | end --> elab A 43 | end; 44 | -------------------------------------------------------------------------------- /basis/Word8ArraySlice.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2002-2025 3 | * 4 | * Standard ML Basis Library 5 | *) 6 | 7 | structure Word8ArraySlice :> MONO_ARRAY_SLICE 8 | where type vector = Word8Vector.vector 9 | where type vector_slice = Word8VectorSlice.slice 10 | where type array = Word8Array.array 11 | where type elem = Word8.word = 12 | struct 13 | open ArraySlice 14 | 15 | type elem = Word8.word 16 | type vector = Word8Vector.vector 17 | type array = elem array 18 | type slice = elem slice 19 | type vector_slice = Word8VectorSlice.slice 20 | 21 | fun copyVec{src, dst, di} = 22 | if di < 0 orelse Array.length dst < di + Word8VectorSlice.length src 23 | then raise Subscript 24 | else copyVec'(src, dst, di, 0) 25 | and copyVec'(src, dst, di, i) = 26 | if i = Word8VectorSlice.length src then () else 27 | ( Array.update(dst, di + i, Word8VectorSlice.sub(src, i)); 28 | copyVec'(src, dst, di, i + 1) ) 29 | end; 30 | -------------------------------------------------------------------------------- /parse/DerivedFormsProgram.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML program derived forms 5 | * 6 | * Definition, Appendix A 7 | *) 8 | 9 | structure DerivedFormsProgram :> DERIVED_FORMS_PROGRAM = 10 | struct 11 | (* Import *) 12 | 13 | open SyntaxCore 14 | open SyntaxModule 15 | open SyntaxProgram 16 | open AnnotationProgram 17 | 18 | 19 | (* Programs [Figure 18] *) 20 | 21 | val TOPDECProgram = Program 22 | 23 | fun EXPProgram(exp, program_opt) = 24 | let 25 | val longvid = LongVId.fromId(VId.fromString "it")@@left(exp) 26 | val atpat = IDAtPat(NONE, longvid)@@left(exp) 27 | val pat = ATPat(atpat)@@at(atpat) 28 | val valbind = PLAINValBind(pat, exp, NONE)@@at(exp) 29 | val dec = VALDec(Seq[]@@left(exp), valbind)@@at(exp) 30 | val strdec = DECStrDec(dec)@@at(exp) 31 | val topdec = STRDECTopDec(strdec, NONE)@@at(exp) 32 | in 33 | Program(topdec, program_opt) 34 | end 35 | end; 36 | -------------------------------------------------------------------------------- /infrastructure/ERROR-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Error handling. 5 | *) 6 | 7 | signature ERROR = 8 | sig 9 | (* Import *) 10 | 11 | type loc = Source.loc 12 | 13 | 14 | (* Export *) 15 | 16 | exception Error 17 | 18 | val print : loc * string -> unit 19 | val warning : loc * string -> unit 20 | val error : loc * string -> 'a 21 | val errorLab : loc * string * IdsCore.Lab -> 'a 22 | val errorVId : loc * string * IdsCore.VId -> 'a 23 | val errorTyCon : loc * string * IdsCore.TyCon -> 'a 24 | val errorTyVar : loc * string * IdsCore.TyVar -> 'a 25 | val errorStrId : loc * string * IdsCore.StrId -> 'a 26 | val errorSigId : loc * string * IdsModule.SigId -> 'a 27 | val errorFunId : loc * string * IdsModule.FunId -> 'a 28 | val errorLongVId : loc * string * IdsCore.longVId -> 'a 29 | val errorLongTyCon : loc * string * IdsCore.longTyCon -> 'a 30 | val errorLongStrId : loc * string * IdsCore.longStrId -> 'a 31 | end; 32 | -------------------------------------------------------------------------------- /basis/IEEE_REAL-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library 5 | * 6 | * Note: Incomplete. 7 | *) 8 | 9 | signature IEEE_REAL = 10 | sig 11 | exception Unordered 12 | datatype real_order = LESS | EQUAL | GREATER | UNORDERED 13 | datatype float_class 14 | = NAN 15 | | INF 16 | | ZERO 17 | | NORMAL 18 | | SUBNORMAL 19 | datatype rounding_mode 20 | = TO_NEAREST 21 | | TO_NEGINF 22 | | TO_POSINF 23 | | TO_ZERO 24 | (* 25 | val setRoundingMode : rounding_mode -> unit 26 | val getRoundingMode : unit -> rounding_mode 27 | type decimal_approx = { 28 | class : float_class, 29 | sign : bool, 30 | digits : int list, 31 | exp : int 32 | } 33 | val toString : decimal_approx -> string 34 | val scan : (char, 'a) StringCvt.reader -> (decimal_approx, 'a) StringCvt.reader 35 | val fromString : string -> decimal_approx option 36 | *) 37 | end; 38 | -------------------------------------------------------------------------------- /test/functor-poly.sml: -------------------------------------------------------------------------------- 1 | (* functor-poly.sml *) 2 | 3 | (* Checks higher-order unification with functors. *) 4 | 5 | (* Example due to 6 | * Dreyer, Harper, Chkravarty, Keller, Modular Type Classes 7 | * Draft 2006 8 | *) 9 | 10 | functor F(type t) = struct val id = (print "Hello\n"; fn x => x) end 11 | 12 | structure A = F(type t = int) 13 | structure B = F(type t = bool) 14 | 15 | val a = A.id 3 16 | val b = B.id true 17 | 18 | functor G(type t) = struct val id = (print "Hello\n"; fn x => x) end 19 | 20 | structure C = G(type t = int) 21 | structure D = G(type t = bool) 22 | 23 | val a = C.id 3 24 | val b = D.id 3 25 | 26 | functor F(type t) = struct val id = (print "Hello\n"; fn x => x) end 27 | 28 | structure A = F(type t = int) : sig val id : int -> int end 29 | structure B = F(type t = bool) : sig val id : bool -> bool end 30 | 31 | functor G(type t) = struct val id = (print "Hello\n"; fn x => x) end 32 | 33 | structure C = G(type t = int) : sig val id : int -> int end 34 | structure D = G(type t = bool) : sig val id : int -> int end 35 | -------------------------------------------------------------------------------- /doc/announce/announcement.txt: -------------------------------------------------------------------------------- 1 | I am pleased to announce the release of `HaMLet'. HaMLet is a faithful implementation of the Standard ML programming language (SML'97) that aims to be 2 | 3 | - an accurate reference implementation of the language specification, 4 | - a platform for experimentation with the language semantics, 5 | - a useful tool for educational purposes. 6 | 7 | The HaMLet sources are intended to be as direct a translation of the language formalisation as possible. Even program evaluation is performed by a direct implementation of the rules of the dynamic semantics. The source code is heavily cross-referenced. 8 | 9 | HaMLet can perform different phases of execution - like parsing, type checking, and evaluation - selectively. In particular, it is possible to execute programs in an untyped manner, thus exploring the universe where even ML programs "can go wrong". 10 | 11 | For download and more information, visit the HaMLet homepage at: 12 | 13 | http://www.ps.uni-sb.de/hamlet/ 14 | 15 | Best regards, 16 | 17 | - Andreas Rossberg 18 | -------------------------------------------------------------------------------- /basis/CharArraySlice.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2002-2025 3 | * 4 | * Standard ML Basis Library 5 | *) 6 | 7 | structure CharArraySlice :> MONO_ARRAY_SLICE 8 | where type vector = CharVector.vector 9 | where type vector_slice = CharVectorSlice.slice 10 | where type array = CharArray.array 11 | where type elem = char = 12 | struct 13 | open ArraySlice 14 | 15 | type elem = Char.char 16 | type vector = CharVector.vector 17 | type array = elem array 18 | type slice = elem slice 19 | type vector_slice = CharVectorSlice.slice 20 | 21 | fun vector sl = CharVector.tabulate(length sl, fn i => sub (sl, i)) 22 | 23 | fun copyVec{src, dst, di} = 24 | if di < 0 orelse Array.length dst < di + CharVectorSlice.length src 25 | then raise Subscript 26 | else copyVec'(src, dst, di, 0) 27 | and copyVec'(src, dst, di, i) = 28 | if i = CharVectorSlice.length src then () else 29 | ( Array.update(dst, di + i, CharVectorSlice.sub(src, i)); 30 | copyVec'(src, dst, di, i + 1) ) 31 | end; 32 | -------------------------------------------------------------------------------- /eval/INTER-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML interfaces 5 | * 6 | * Definition, Section 7.2 7 | *) 8 | 9 | signature INTER = 10 | sig 11 | (* Import *) 12 | 13 | type longTyCon = IdsCore.longTyCon 14 | 15 | type Env = DynamicObjectsCore.Env 16 | type Int = DynamicObjectsModule.Int 17 | type ValInt = DynamicObjectsModule.ValInt 18 | type TyInt = DynamicObjectsModule.TyInt 19 | type StrInt = DynamicObjectsModule.StrInt 20 | 21 | 22 | (* Operations *) 23 | 24 | val empty : Int 25 | 26 | val fromSI : StrInt -> Int 27 | val fromTI : TyInt -> Int 28 | val fromVI : ValInt -> Int 29 | val fromVIandTI : ValInt * TyInt -> Int 30 | 31 | val SIof : Int -> StrInt 32 | val TIof : Int -> TyInt 33 | val VIof : Int -> ValInt 34 | 35 | val plus : Int * Int -> Int 36 | 37 | val findLongTyCon : Int * longTyCon -> ValInt option 38 | 39 | val Inter : Env -> Int 40 | val cutdown : Env * Int -> Env 41 | end; 42 | -------------------------------------------------------------------------------- /parse/INFIX-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML infix resolution 5 | * 6 | * Definition, Section 2.6 7 | *) 8 | 9 | signature INFIX = 10 | sig 11 | (* Import *) 12 | 13 | type Op = SyntaxCore.Op 14 | type VId = SyntaxCore.VId 15 | type longVId = SyntaxCore.longVId 16 | type Exp = SyntaxCore.Exp 17 | type Pat = SyntaxCore.Pat 18 | type AtExp = SyntaxCore.AtExp 19 | type AtPat = SyntaxCore.AtPat 20 | 21 | 22 | (* Modifying fixity status *) 23 | 24 | datatype Assoc = LEFT | RIGHT 25 | 26 | type InfStatus = Assoc * int 27 | type InfEnv = InfStatus VIdMap.map (* [J] *) 28 | 29 | val empty : InfEnv 30 | val assign : InfEnv * VId.Id list * InfStatus -> InfEnv 31 | val cancel : InfEnv * VId.Id list -> InfEnv 32 | 33 | (* Resolving phrases containing infixed identifiers *) 34 | 35 | val parseExp : InfEnv * AtExp list -> Exp 36 | val parsePat : InfEnv * AtPat list -> Pat 37 | val parseFmrule : InfEnv * AtPat list -> Op option * VId * AtPat list 38 | end; 39 | -------------------------------------------------------------------------------- /compile-js/JS_TRANSLATE_ID-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2013-2025 3 | * 4 | * Translation of identifiers into JavaScript. 5 | *) 6 | 7 | signature JS_TRANSLATE_ID = 8 | sig 9 | (* Import *) 10 | 11 | type Lab = SyntaxCore.Lab 12 | type VId = SyntaxCore.VId 13 | type StrId = SyntaxCore.StrId 14 | type FunId = SyntaxModule.FunId 15 | type longVId = SyntaxCore.longVId 16 | type longStrId = SyntaxCore.longStrId 17 | 18 | type name = JSSyntax.name 19 | type var = JSSyntax.var 20 | type expr = JSSyntax.expr 21 | 22 | 23 | (* Export *) 24 | 25 | val translateLab' : Lab.Lab -> name 26 | val translateVId' : VId.Id -> var 27 | val translateStrId' : StrId.Id -> var 28 | val translateFunId' : FunId.Id -> var 29 | 30 | val translateLab : Lab -> name 31 | val translateVId : VId -> var 32 | val translateStrId : StrId -> var 33 | val translateFunId : FunId -> var 34 | 35 | val translateLongVId : longVId -> expr 36 | val translateLongStrId : longStrId -> expr 37 | end; 38 | -------------------------------------------------------------------------------- /smlnj-lib/lib-base.sml: -------------------------------------------------------------------------------- 1 | (* lib-base.sml 2 | * 3 | * COPYRIGHT (c) 1993 by AT&T Bell Laboratories. See COPYRIGHT file for details. 4 | *) 5 | 6 | structure LibBase : LIB_BASE = 7 | struct 8 | 9 | (* raised to report unimplemented features *) 10 | exception Unimplemented of string 11 | 12 | (* raised to report internal errors *) 13 | exception Impossible of string 14 | 15 | (* raised by searching operations *) 16 | exception NotFound 17 | 18 | (* raise the exception Fail with a standard format message. *) 19 | fun failure {module, func, msg} = 20 | raise (Fail(concat[module, ".", func, ": ", msg])) 21 | 22 | val version = { 23 | date = "June 1, 1996", 24 | system = "SML/NJ Library", 25 | version_id = [1, 0] 26 | } 27 | 28 | fun f ([], l) = l 29 | | f ([x : int], l) = (Int.toString x)::l 30 | | f (x::r, l) = (Int.toString x) :: "." :: f(r, l) 31 | 32 | val banner = concat ( 33 | #system version :: ", Version " :: 34 | f (#version_id version, [", ", #date version])) 35 | 36 | end (* LibBase *) 37 | ; 38 | -------------------------------------------------------------------------------- /smlnj-lib/queue.sml: -------------------------------------------------------------------------------- 1 | (* queue.sml 2 | * 3 | * COPYRIGHT (c) 1993 by AT&T Bell Laboratories. See COPYRIGHT file for details. 4 | * 5 | * Imperative fifos 6 | * 7 | *) 8 | 9 | structure Queue :> QUEUE = 10 | struct 11 | type 'a queue = 'a Fifo.fifo ref 12 | 13 | exception Dequeue = Fifo.Dequeue 14 | 15 | fun mkQueue () = ref Fifo.empty 16 | 17 | fun clear q = (q := Fifo.empty) 18 | 19 | fun enqueue (q,x) = q := (Fifo.enqueue (!q, x)) 20 | 21 | fun dequeue q = let 22 | val (newq, x) = Fifo.dequeue (!q) 23 | in 24 | q := newq; 25 | x 26 | end 27 | 28 | fun delete (q, pred) = (q := Fifo.delete (!q, pred)) 29 | fun head q = Fifo.head (!q) 30 | fun peek q = Fifo.peek (!q) 31 | fun isEmpty q = Fifo.isEmpty (!q) 32 | fun length q = Fifo.length (!q) 33 | fun contents q = Fifo.contents (!q) 34 | fun app f q = Fifo.app f (!q) 35 | fun map f q = ref(Fifo.map f (!q)) 36 | fun foldl f b q = Fifo.foldl f b (!q) 37 | fun foldr f b q = Fifo.foldr f b (!q) 38 | 39 | end 40 | -------------------------------------------------------------------------------- /basis/LIST_PAIR-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library 5 | *) 6 | 7 | signature LIST_PAIR = 8 | sig 9 | exception UnequalLengths 10 | val zip : 'a list * 'b list -> ('a * 'b) list 11 | val zipEq : 'a list * 'b list -> ('a * 'b) list 12 | val unzip : ('a * 'b) list -> 'a list * 'b list 13 | val app : ('a * 'b -> unit) -> 'a list * 'b list -> unit 14 | val appEq : ('a * 'b -> unit) -> 'a list * 'b list -> unit 15 | val map : ('a * 'b -> 'c) -> 'a list * 'b list -> 'c list 16 | val mapEq : ('a * 'b -> 'c) -> 'a list * 'b list -> 'c list 17 | val foldl : ('a * 'b * 'c -> 'c) -> 'c -> 'a list * 'b list -> 'c 18 | val foldr : ('a * 'b * 'c -> 'c) -> 'c -> 'a list * 'b list -> 'c 19 | val foldlEq : ('a * 'b * 'c -> 'c) -> 'c -> 'a list * 'b list -> 'c 20 | val foldrEq : ('a * 'b * 'c -> 'c) -> 'c -> 'a list * 'b list -> 'c 21 | val all : ('a * 'b -> bool) -> 'a list * 'b list -> bool 22 | val exists : ('a * 'b -> bool) -> 'a list * 'b list -> bool 23 | val allEq : ('a * 'b -> bool) -> 'a list * 'b list -> bool 24 | end; 25 | -------------------------------------------------------------------------------- /test/flexrecord2.sml: -------------------------------------------------------------------------------- 1 | (* flexrecord2.sml *) 2 | 3 | (* Checks type inference for flexible records with large context. *) 4 | 5 | (* Not supported by Hamlet, since probably not intended by Definition. *) 6 | 7 | (* Examples by Stephen Weeks *) 8 | 9 | (* flexrecord2 *) 10 | val _ = 11 | let 12 | val g = #foo 13 | val _ = g {foo = 13} 14 | val _ = g {foo = "yes"} 15 | in 16 | () 17 | end 18 | (* flexrecord2 *) 19 | 20 | (* flexrecord3 *) 21 | val _ = 22 | let 23 | val g = #foo 24 | val _ = g {foo = 13, goo = 1.0} 25 | val _ = g {foo = "yes", goo = 1.0} 26 | in 27 | () 28 | end 29 | (* flexrecord3 *) 30 | 31 | (* flexrecord4 *) 32 | val _ = 33 | let 34 | val g = #foo 35 | val _ = g {foo = 13, goo = 1.0} 36 | val _ = g {foo = "yes", goo = false} 37 | in 38 | () 39 | end; 40 | (* flexrecord4 *) 41 | 42 | (* flexrecord5 *) 43 | val _ = 44 | let 45 | val g = #foo 46 | val f = fn x => g {foo = "yes", goo = x} 47 | val _ = g {foo = 13, goo = 1.0} 48 | in 49 | f 2; f true 50 | end; 51 | (* flexrecord5 *) 52 | -------------------------------------------------------------------------------- /infrastructure/Makefile.depend.in: -------------------------------------------------------------------------------- 1 | # Infrastructure 2 | ERROR-sig.$(EXT) : ../syntax/Source.$(EXT) ../syntax/IdsCore.$(EXT) ../syntax/IdsModule.$(EXT) 3 | Error.$(EXT) : ERROR-sig.$(EXT) ../syntax/Source.$(EXT) ../syntax/IdsCore.$(EXT) ../syntax/IdsModule.$(EXT) ../syntax/Lab.$(EXT) ../syntax/TyVar.$(EXT) 4 | FIN_MAP-sig.$(EXT) : ../smlnj-lib/ord-map-sig.$(EXT) 5 | FIN_SET-sig.$(EXT) : ../smlnj-lib/ord-set-sig.$(EXT) 6 | FinMapFn.$(EXT) : ../smlnj-lib/ord-key-sig.$(EXT) FIN_MAP-sig.$(EXT) ../smlnj-lib/binary-map-fn.$(EXT) ../smlnj-lib/lib-base.$(EXT) 7 | FinSetFn.$(EXT) : ../smlnj-lib/ord-key-sig.$(EXT) FIN_SET-sig.$(EXT) ../smlnj-lib/binary-set-fn.$(EXT) ../smlnj-lib/lib-base.$(EXT) 8 | GENERIC_ENV-sig.$(EXT) : ../syntax/IdsCore.$(EXT) 9 | GenericEnvFn.$(EXT) : GENERIC_ENV-sig.$(EXT) ../syntax/IdsCore.$(EXT) 10 | PPMisc.$(EXT) : PP_MISC-sig.$(EXT) PrettyPrint.$(EXT) 11 | PP_MISC-sig.$(EXT) : PrettyPrint.$(EXT) 12 | PRETTY_PRINT-sig.$(EXT) : 13 | PrettyPrint.$(EXT) : PRETTY_PRINT-sig.$(EXT) 14 | PROP-sig.$(EXT) : 15 | Prop.$(EXT) : PROP-sig.$(EXT) 16 | STAMP-sig.$(EXT) : 17 | Stamp.$(EXT) : STAMP-sig.$(EXT) FinMapFn.$(EXT) 18 | -------------------------------------------------------------------------------- /infrastructure/FinMapFn.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML finite maps 5 | * 6 | * Definition, Section 4.2 7 | *) 8 | 9 | functor FinMapFn(Key : ORD_KEY) :> 10 | FIN_MAP where type Key.ord_key = Key.ord_key = 11 | struct 12 | structure BinaryMap = BinaryMapFn(Key) 13 | open BinaryMap 14 | 15 | exception NotFound = LibBase.NotFound 16 | exception Duplicate 17 | 18 | fun fromList kvs = 19 | List.foldl 20 | (fn((k, v), m) => 21 | if inDomain(m, k) then raise Duplicate else insert(m, k, v) 22 | ) empty kvs 23 | 24 | fun extend(m, (k, v)) = insert(m, k, v) 25 | fun delete(m, k) = #1(remove(m, k)) handle LibBase.NotFound => m 26 | fun difference(m, n) = filteri (fn(k, _) => not(inDomain(n, k))) m 27 | 28 | fun all p = foldl (fn(v, b) => b andalso p v) true 29 | fun exists p = foldl (fn(v, b) => b orelse p v) false 30 | fun alli p = foldli (fn(k, v, b) => b andalso p(k, v)) true 31 | fun existsi p = foldli (fn(k, v, b) => b orelse p(k, v)) false 32 | 33 | fun disjoint(m1, m2) = isEmpty(intersectWith #2 (m1, m2)) 34 | end; 35 | -------------------------------------------------------------------------------- /eval/PPDynamicBasis.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML pretty printing of the dynamic basis 5 | *) 6 | 7 | structure PPDynamicBasis : PP_DYNAMIC_BASIS = 8 | struct 9 | (* Import *) 10 | 11 | type Basis = DynamicObjectsModule.Basis 12 | type State = DynamicObjectsCore.State 13 | 14 | open PrettyPrint 15 | 16 | infixr ^^ ^/^ 17 | 18 | 19 | (* Simple objects *) 20 | 21 | fun ppFunId funid = text(FunId.toString funid) 22 | fun ppSigId sigid = text(SigId.toString sigid) 23 | 24 | 25 | (* Environments *) 26 | 27 | fun ppFunEnv F = 28 | FunIdMap.foldri 29 | (fn(funid, _, doc) => 30 | hbox(text "functor" ^/^ ppFunId funid) ^/^ doc 31 | ) empty F 32 | 33 | fun ppSigEnv G = 34 | SigIdMap.foldri 35 | (fn(sigid, _, doc) => 36 | hbox(text "signature" ^/^ ppSigId sigid) ^/^ doc 37 | ) empty G 38 | 39 | 40 | (* Basis *) 41 | 42 | fun ppBasis(s, (F, G, E)) = 43 | vbox( 44 | ppSigEnv G ^/^ 45 | ppFunEnv F ^/^ 46 | PPDynamicEnv.ppEnv(s, E) ^/^ 47 | text "" 48 | ) 49 | end; 50 | -------------------------------------------------------------------------------- /main/SML-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML implementation main structure 5 | *) 6 | 7 | signature SML = 8 | sig 9 | val basisPath : string option ref 10 | 11 | val parseString : string -> unit 12 | val elabString : string -> unit 13 | val evalString : string -> unit 14 | val execString : string -> unit 15 | val compileJSString : string -> unit 16 | 17 | val parseFile : string -> unit 18 | val elabFile : string -> unit 19 | val evalFile : string -> unit 20 | val execFile : string -> unit 21 | val compileJSFile : string -> unit 22 | 23 | val parseFiles : string list -> unit 24 | val elabFiles : string list -> unit 25 | val evalFiles : string list -> unit 26 | val execFiles : string list -> unit 27 | val compileJSFiles : string list -> unit 28 | 29 | val parseSession : unit -> unit 30 | val elabSession : unit -> unit 31 | val evalSession : unit -> unit 32 | val execSession : unit -> unit 33 | val compileJSSession : unit -> unit 34 | end; 35 | -------------------------------------------------------------------------------- /elab/INITIAL_STATIC_ENV-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML core view of the initial static basis 5 | * 6 | * Definition, Appendix C 7 | *) 8 | 9 | signature INITIAL_STATIC_ENV = 10 | sig 11 | (* Import *) 12 | 13 | type Type = StaticObjectsCore.Type 14 | type TyName = StaticObjectsCore.TyName 15 | type TyNameSet = StaticObjectsCore.TyNameSet 16 | type OverloadingClass = StaticObjectsCore.OverloadingClass 17 | type Env = StaticObjectsCore.Env 18 | 19 | 20 | (* Predefined monomorphic types [Figure 24] *) 21 | 22 | val tBool : TyName 23 | val tInt : TyName 24 | val tWord : TyName 25 | val tReal : TyName 26 | val tString : TyName 27 | val tChar : TyName 28 | val tExn : TyName 29 | 30 | val tauBool : Type 31 | val tauInt : Type 32 | val tauWord : Type 33 | val tauReal : Type 34 | val tauString : Type 35 | val tauChar : Type 36 | val tauExn : Type 37 | 38 | (* Initial environment [Appendix C] *) 39 | 40 | val T0 : TyNameSet 41 | val E0 : Env 42 | end; 43 | -------------------------------------------------------------------------------- /syntax/ANNOTATION-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2013-2025 3 | * 4 | * Helpers for abstract syntax annotations 5 | *) 6 | 7 | signature ANNOTATION = 8 | sig 9 | include PROP 10 | 11 | type 'a annotation = (Source.loc, 'a) cons (* [A] *) 12 | datatype ('a, 'b) phrase = @@ of 'a * 'b annotation 13 | 14 | exception Annotation 15 | 16 | val syntax : ('a, 'b) phrase -> 'a 17 | val annotation : ('a, 'b) phrase -> 'b annotation 18 | 19 | val loc : 'a annotation -> Source.loc 20 | val fromLoc : Source.loc -> 'a annotation 21 | val nowhere : unit -> 'a annotation 22 | val copy : 'a annotation -> 'a annotation 23 | 24 | val at : ('a, 'b) phrase -> 'c annotation 25 | val left : ('a, 'b) phrase -> 'c annotation 26 | val right : ('a, 'b) phrase -> 'c annotation 27 | val over : ('a, 'b) phrase * ('c, 'd) phrase -> 'e annotation 28 | val overSome : ('a, 'b) phrase * ('c, 'd) phrase option -> 'e annotation 29 | val overAll : ('a, 'b) phrase list -> 'e annotation 30 | 31 | val --> : 'a * 'a prop -> 'a (* raises Annotation *) 32 | end; 33 | -------------------------------------------------------------------------------- /basis/Math.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library 5 | *) 6 | 7 | structure Math :> MATH where type real = real = 8 | struct 9 | type real = real 10 | 11 | val e = use{b = "Math.e"} () : real 12 | val pi = use{b = "Math.pi"} () : real 13 | 14 | val sqrt = use{b = "Math.sqrt"} : real -> real 15 | val sin = use{b = "Math.sin"} : real -> real 16 | val cos = use{b = "Math.cos"} : real -> real 17 | val tan = use{b = "Math.tan"} : real -> real 18 | val asin = use{b = "Math.asin"} : real -> real 19 | val acos = use{b = "Math.acos"} : real -> real 20 | val atan = use{b = "Math.atan"} : real -> real 21 | val atan2 = use{b = "Math.atan2"} : real * real -> real 22 | val exp = use{b = "Math.exp"} : real -> real 23 | val pow = use{b = "Math.pow"} : real * real -> real 24 | val ln = use{b = "Math.ln"} : real -> real 25 | val log10 = use{b = "Math.log10"} : real -> real 26 | val sinh = use{b = "Math.sinh"} : real -> real 27 | val cosh = use{b = "Math.cosh"} : real -> real 28 | val tanh = use{b = "Math.tanh"} : real -> real 29 | end; 30 | -------------------------------------------------------------------------------- /parse/BindingContext.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML context for binding analysis 5 | *) 6 | 7 | structure BindingContext : BINDING_CONTEXT = 8 | struct 9 | (* Import *) 10 | 11 | open IdsCore 12 | open BindingObjectsCore 13 | 14 | 15 | (* Projections [Section 4.3] *) 16 | 17 | fun Uof(U, E) = U 18 | fun Eof(U, E) = E 19 | 20 | 21 | (* Modification [Section 4.3] *) 22 | 23 | infix plus plusU plusVE plusTE plusVEandTE plusE 24 | 25 | val op plus = BindingEnv.plus 26 | 27 | fun (U, E) plusU U' = (TyVarSet.union(U, U'), E) 28 | fun (U, E) plusE E' = (U, E plus E') 29 | fun (U, E) plusVE VE = (U, E plus BindingEnv.fromVE VE) 30 | fun (U, E) plusTE TE = (U, E plus BindingEnv.fromTE TE) 31 | fun (U, E) plusVEandTE (VE, TE) = (U, E plus BindingEnv.fromVEandTE (VE, TE)) 32 | 33 | 34 | (* Application (lookup) [Section 4.3] *) 35 | 36 | fun findLongVId((U, E), longvid) = BindingEnv.findLongVId(E, longvid) 37 | fun findLongTyCon((U, E), longtycon) = BindingEnv.findLongTyCon(E, longtycon) 38 | fun findLongStrId((U, E), longstrid) = BindingEnv.findLongStrId(E, longstrid) 39 | end; 40 | -------------------------------------------------------------------------------- /smlnj-lib/LICENSE.txt: -------------------------------------------------------------------------------- 1 | STANDARD ML OF NEW JERSEY COPYRIGHT NOTICE, LICENSE AND DISCLAIMER. 2 | 3 | Copyright (c) 1989-1998 by Lucent Technologies 4 | 5 | Permission to use, copy, modify, and distribute this software and its 6 | documentation for any purpose and without fee is hereby granted, 7 | provided that the above copyright notice appear in all copies and that 8 | both the copyright notice and this permission notice and warranty 9 | disclaimer appear in supporting documentation, and that the name of 10 | Lucent Technologies, Bell Labs or any Lucent entity not be used in 11 | advertising or publicity pertaining to distribution of the software 12 | without specific, written prior permission. 13 | 14 | Lucent disclaims all warranties with regard to this software, including 15 | all implied warranties of merchantability and fitness. In no event shall 16 | Lucent be liable for any special, indirect or consequential damages or 17 | any damages whatsoever resulting from loss of use, data or profits, 18 | whether in an action of contract, negligence or other tortious action, 19 | arising out of or in connection with the use or performance of this 20 | software. 21 | -------------------------------------------------------------------------------- /syntax/PP_CORE-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2007-2025 3 | * 4 | * Printer for abstract core syntax 5 | *) 6 | 7 | signature PP_CORE = 8 | sig 9 | type VId = SyntaxCore.VId 10 | type TyCon = SyntaxCore.TyCon 11 | type StrId = SyntaxCore.StrId 12 | type longVId = SyntaxCore.longVId 13 | type longTyCon = SyntaxCore.longTyCon 14 | type longStrId = SyntaxCore.longStrId 15 | type TyVar = SyntaxCore.TyVar 16 | type Ty = SyntaxCore.Ty 17 | type Dec = SyntaxCore.Dec 18 | type 'a seq = 'a SyntaxCore.seq 19 | 20 | val ppVId : TextIO.outstream * int * VId -> unit 21 | val ppTyCon : TextIO.outstream * int * TyCon -> unit 22 | val ppStrId : TextIO.outstream * int * StrId -> unit 23 | val ppLongVId : TextIO.outstream * int * longVId -> unit 24 | val ppLongTyCon : TextIO.outstream * int * longTyCon -> unit 25 | val ppLongStrId : TextIO.outstream * int * longStrId -> unit 26 | val ppTyVarseq : TextIO.outstream * int * TyVar seq -> unit 27 | 28 | val ppTy : TextIO.outstream * int * Ty -> unit 29 | val ppDec : TextIO.outstream * int * Dec -> unit 30 | end; 31 | -------------------------------------------------------------------------------- /test/where-and.sml: -------------------------------------------------------------------------------- 1 | (* where-and.sml *) 2 | 3 | (* Checks parsing of where type ... and derived form. *) 4 | 5 | signature S = sig type t and u end 6 | 7 | signature T = S where type t = int and type u = bool 8 | and U = S where type t = int and type u = bool 9 | 10 | signature V = 11 | sig 12 | structure A : S where type t = int and type u = bool 13 | and B : S where type t = int and type u = bool 14 | end 15 | 16 | structure A : S where type t = int and type u = bool = 17 | struct 18 | type t = int 19 | type u = bool 20 | end 21 | 22 | structure B = A : S where type t = int and type u = bool 23 | and C = A : S where type t = int and type u = bool 24 | 25 | functor F(X : S where type t = int and type u = bool) : 26 | S where type t = int and type u = bool = 27 | X : S where type t = int and type u = bool 28 | and G(Y : S where type t = int and type u = bool) : 29 | S where type t = int and type u = bool = 30 | Y : S where type t = int and type u = bool 31 | 32 | signature W = 33 | sig 34 | type t and u and v 35 | end 36 | 37 | signature W' = W where type t = int and type u = int where type v = int 38 | and W'' = W; 39 | -------------------------------------------------------------------------------- /smlnj-lib/queue-sig.sml: -------------------------------------------------------------------------------- 1 | (* queue-sig.sml 2 | * 3 | * COPYRIGHT (c) 1993 by AT&T Bell Laboratories. See COPYRIGHT file for details. 4 | * 5 | * Imperative fifos 6 | * 7 | *) 8 | 9 | signature QUEUE = 10 | sig 11 | type 'a queue 12 | 13 | exception Dequeue 14 | 15 | val mkQueue : unit -> 'a queue 16 | (* make a new queue *) 17 | val clear : 'a queue -> unit 18 | (* remove all elements *) 19 | val isEmpty : 'a queue -> bool 20 | (* test for empty queue *) 21 | val enqueue : 'a queue * 'a -> unit 22 | (* enqueue an element at the rear *) 23 | val dequeue : 'a queue -> 'a 24 | (* remove the front element (raise Dequeue if empty) *) 25 | val delete : ('a queue * ('a -> bool)) -> unit 26 | (* delete all elements satisfying the given predicate *) 27 | val head : 'a queue -> 'a 28 | val peek : 'a queue -> 'a option 29 | val length : 'a queue -> int 30 | val contents : 'a queue -> 'a list 31 | val app : ('a -> unit) -> 'a queue -> unit 32 | val map : ('a -> 'b) -> 'a queue -> 'b queue 33 | val foldl : ('a * 'b -> 'b) -> 'b -> 'a queue -> 'b 34 | val foldr : ('a * 'b -> 'b) -> 'b -> 'a queue -> 'b 35 | 36 | end 37 | -------------------------------------------------------------------------------- /fix/ListPair.sml: -------------------------------------------------------------------------------- 1 | (* Eq variants do not exist in older SML versions *) 2 | 3 | structure ListPair = 4 | struct 5 | open ListPair 6 | 7 | exception UnequalLengths 8 | 9 | fun zipEq(x::xs, y::ys) = (x, y)::zipEq(xs, ys) 10 | | zipEq(nil, nil) = nil 11 | | zipEq _ = raise UnequalLengths 12 | 13 | fun appEq f (x::xs, y::ys) = ( f(x, y); appEq f (xs, ys) ) 14 | | appEq f (nil, nil) = () 15 | | appEq f _ = raise UnequalLengths 16 | 17 | fun mapEq f (x::xs, y::ys) = f(x, y)::mapEq f (xs, ys) 18 | | mapEq f (nil, nil) = nil 19 | | mapEq f _ = raise UnequalLengths 20 | 21 | fun foldlEq f c (x::xs, y::ys) = foldlEq f (f(x, y, c)) (xs, ys) 22 | | foldlEq f c (nil, nil) = c 23 | | foldlEq f c _ = raise UnequalLengths 24 | 25 | fun foldrEq f c (x::xs, y::ys) = f(x, y, foldrEq f c (xs, ys)) 26 | | foldrEq f c (nil, nil) = c 27 | | foldrEq f c _ = raise UnequalLengths 28 | 29 | fun allEq f ([], []) = true 30 | | allEq f (x::xs, y::ys) = f(x, y) andalso allEq f (xs, ys) 31 | | allEq f _ = false 32 | end 33 | -------------------------------------------------------------------------------- /basis/MONO_VECTOR-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library 5 | *) 6 | 7 | signature MONO_VECTOR = 8 | sig 9 | type vector 10 | type elem 11 | val maxLen : int 12 | val fromList : elem list -> vector 13 | val tabulate : int * (int -> elem) -> vector 14 | val length : vector -> int 15 | val sub : vector * int -> elem 16 | val update : vector * int * elem -> vector 17 | val concat : vector list -> vector 18 | val appi : (int * elem -> unit) -> vector -> unit 19 | val app : (elem -> unit) -> vector -> unit 20 | val mapi : (int * elem -> elem) -> vector -> vector 21 | val map : (elem -> elem) -> vector -> vector 22 | val foldli : (int * elem * 'a -> 'a) -> 'a -> vector -> 'a 23 | val foldri : (int * elem * 'a -> 'a) -> 'a -> vector -> 'a 24 | val foldl : (elem * 'a -> 'a) -> 'a -> vector -> 'a 25 | val foldr : (elem * 'a -> 'a) -> 'a -> vector -> 'a 26 | val findi : (int * elem -> bool) -> vector -> (int * elem) option 27 | val find : (elem -> bool) -> vector -> elem option 28 | val exists : (elem -> bool) -> vector -> bool 29 | val all : (elem -> bool) -> vector -> bool 30 | val collate : (elem * elem -> order) -> vector * vector -> order 31 | end; 32 | -------------------------------------------------------------------------------- /basis/VECTOR-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library 5 | *) 6 | 7 | signature VECTOR = 8 | sig 9 | eqtype 'a vector 10 | val maxLen : int 11 | val fromList : 'a list -> 'a vector 12 | val tabulate : int * (int -> 'a) -> 'a vector 13 | val length : 'a vector -> int 14 | val sub : 'a vector * int -> 'a 15 | val update : 'a vector * int * 'a -> 'a vector 16 | val concat : 'a vector list -> 'a vector 17 | val appi : (int * 'a -> unit) -> 'a vector -> unit 18 | val app : ('a -> unit) -> 'a vector -> unit 19 | val mapi : (int * 'a -> 'b) -> 'a vector -> 'b vector 20 | val map : ('a -> 'b) -> 'a vector -> 'b vector 21 | val foldli : (int * 'a * 'b -> 'b) -> 'b -> 'a vector -> 'b 22 | val foldri : (int * 'a * 'b -> 'b) -> 'b -> 'a vector -> 'b 23 | val foldl : ('a * 'b -> 'b) -> 'b -> 'a vector -> 'b 24 | val foldr : ('a * 'b -> 'b) -> 'b -> 'a vector -> 'b 25 | val findi : (int * 'a -> bool) -> 'a vector -> (int * 'a) option 26 | val find : ('a -> bool) -> 'a vector -> 'a option 27 | val exists : ('a -> bool) -> 'a vector -> bool 28 | val all : ('a -> bool) -> 'a vector -> bool 29 | val collate : ('a * 'a -> order) -> 'a vector * 'a vector -> order 30 | end; 31 | -------------------------------------------------------------------------------- /main/wrap-smlsharp.sml: -------------------------------------------------------------------------------- 1 | use "fix/Word-smlsharp.sml"; 2 | use "fix/CommandLine-smlsharp.sml"; 3 | use "hamlet.sml"; 4 | use "main/MAIN-sig.sml"; 5 | use "main/Main.sml"; 6 | Sml.basisPath := OS.FileSys.getDir() ^ "/basis"; 7 | val _ = Main.main() 8 | 9 | 10 | 11 | 12 | (* Unsuccessful attempts to hack around flushing bug in SML#... 13 | let 14 | val stdout = TextIO.getOutstream TextIO.stdOut 15 | in 16 | TextIO.StreamIO.setBufferMode(stdout, IO.NO_BUF); 17 | TextIO.setOutstream(TextIO.stdOut, stdout) 18 | end; 19 | structure TextIO = 20 | struct 21 | open TextIO 22 | fun flushOut os = 23 | (TextIO.setOutstream(os, TextIO.getOutstream os); 24 | let 25 | val os' = TextIO.getOutstream os 26 | val _ = TextIO.StreamIO.flushOut os' 27 | val (writer, m) = TextIO.StreamIO.getWriter os' 28 | val TextPrimIO.WR{writeVec=SOME writeVec,...} = writer 29 | val _ = writeVec(CharVectorSlice.full "") 30 | val os'' = TextIO.StreamIO.mkOutstream(writer, m) 31 | in 32 | TextIO.setOutstream(os, os'') 33 | end) 34 | end; 35 | val _ = TextIO.output(TextIO.stdOut, "$ ") 36 | val _ = TextIO.flushOut TextIO.stdOut 37 | val s = TextIO.inputLine TextIO.stdIn 38 | *) 39 | -------------------------------------------------------------------------------- /basis/OS_FILE_SYS-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library 5 | * 6 | * Note: Incomplete. 7 | *) 8 | 9 | signature OS_FILE_SYS = 10 | sig 11 | (* 12 | type dirstream 13 | val openDir : string -> dirstream 14 | val readDir : dirstream -> string option 15 | val rewindDir : dirstream -> unit 16 | val closeDir : dirstream -> unit 17 | *) 18 | val chDir : string -> unit 19 | val getDir : unit -> string 20 | val mkDir : string -> unit 21 | val rmDir : string -> unit 22 | val isDir : string -> bool 23 | (* 24 | val isLink : string -> bool 25 | val readLink : string -> string 26 | val fullPath : string -> string 27 | val realPath : string -> string 28 | val modTime : string -> Time.time 29 | val fileSize : string -> Position.int 30 | val setTime : string * Time.time option -> unit 31 | val remove : string -> unit 32 | val rename : {old : string, new : string} -> unit 33 | datatype access_mode = A_READ | A_WRITE | A_EXEC 34 | val access : string * access_mode list -> bool 35 | val tmpName : unit -> string 36 | eqtype file_id 37 | val fileId : string -> file_id 38 | val hash : file_id -> word 39 | val compare : file_id * file_id -> order 40 | *) 41 | end; 42 | -------------------------------------------------------------------------------- /basis/values.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library top-level values 5 | * 6 | * Note: Overloaded values are all primitive. 7 | *) 8 | 9 | fun a1 <> a2 = Bool.not(a1 = a2) 10 | 11 | open General 12 | 13 | val getOpt = Option.getOpt 14 | val isSome = Option.isSome 15 | val valOf = Option.valOf 16 | val not = Bool.not 17 | val real = Real.fromInt 18 | val trunc = Real.trunc 19 | val floor = Real.floor 20 | val ceil = Real.ceil 21 | val round = Real.round 22 | val ord = Char.ord 23 | val chr = Char.chr 24 | val size = String.size 25 | val str = String.str 26 | val concat = String.concat 27 | val implode = String.implode 28 | val explode = String.explode 29 | val substring = String.substring 30 | val op^ = String.^ 31 | val null = List.null 32 | val hd = List.hd 33 | val tl = List.tl 34 | val length = List.length 35 | val rev = List.rev 36 | val op@ = List.@ 37 | val app = List.app 38 | val map = List.map 39 | val foldr = List.foldr 40 | val foldl = List.foldl 41 | val print = TextIO.print 42 | val vector = Vector.fromList 43 | val use = use : string -> unit; 44 | -------------------------------------------------------------------------------- /syntax/Source.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Helpers for handling source strings 5 | *) 6 | 7 | structure Source : SOURCE = 8 | struct 9 | type source = string 10 | type pos = int * int 11 | type region = pos * pos 12 | type loc = {file : string option, region : region} 13 | 14 | val nowhere = {file = NONE, region = ((0, 0), (0, 0))} 15 | 16 | fun after(line, col) = (line, col + 1) 17 | 18 | fun at'(r : region) = r 19 | fun left'(r : region) = (#1 r, after(#1 r)) 20 | fun right'(r : region) = (#2 r, after(#2 r)) 21 | fun over'(r1 : region, r2 : region) = (#1 r1, #2 r2) 22 | 23 | fun transform1 f (loc : loc) = {file = #file loc, region = f(#region loc)} 24 | fun transform2 f (loc1 : loc, loc2 : loc) = 25 | {file = #file loc1, region = f(#region loc1, #region loc2)} 26 | 27 | val at = transform1 at' 28 | val left = transform1 left' 29 | val right = transform1 right' 30 | val over = transform2 over' 31 | 32 | fun comparePair compareOne ((x1, y1), (x2, y2)) = 33 | case compareOne(x1, x2) of 34 | EQUAL => compareOne(y1, y2) 35 | | order => order 36 | 37 | fun compare(loc1 : loc, loc2 : loc) = 38 | comparePair (comparePair Int.compare) (#region loc1, #region loc2) 39 | end; 40 | -------------------------------------------------------------------------------- /doc/announce/announcement1.1.txt: -------------------------------------------------------------------------------- 1 | I am pleased to announce the release of version 1.1 of HaMLet. The new version mainly featues changes to the library: 2 | 3 | - conformance with the latest incarnation of the SML Basis Library 4 | specification (http://SML.sourceforge.net/Basis/), 5 | - a bunch of additional library structures, 6 | - some bug fixes. 7 | 8 | HaMLet is a faithful implementation of the Standard ML programming language (SML'97) that aims to be 9 | 10 | - an accurate reference implementation of the language specification, 11 | - a platform for experimentation with the language semantics, 12 | - a useful tool for educational purposes. 13 | 14 | The HaMLet sources are intended to be as direct a translation of the language formalisation as possible. Even program evaluation is performed by a direct implementation of the rules of the dynamic semantics. The source code is heavily cross-referenced. 15 | 16 | HaMLet can perform different phases of execution - like parsing, type checking, and evaluation - selectively. In particular, it is possible to execute programs in an untyped manner, thus exploring the universe where even ML programs "can go wrong". 17 | 18 | For download and more information, visit the HaMLet homepage at: 19 | 20 | http://www.ps.uni-sb.de/hamlet/ 21 | -------------------------------------------------------------------------------- /parse/BindingObjectsCore.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML objects for binding analysis of the core 5 | * 6 | * Definition, Section 2.9 7 | * 8 | * Notes: 9 | * - The "syntactic restrictions" defined in the Definition are not purely 10 | * syntactic. E.g. the restriction that valbinds may not bind the same vid 11 | * twice [2nd bullet] cannot be checked without proper binding analysis 12 | * that computes identifier status. 13 | * - Also, checking of type variable shadowing [last bullet] is a global 14 | * check dependent on context. Moreover, it requires the transformation from 15 | * Section 4.6 to be done first. 16 | *) 17 | 18 | structure BindingObjectsCore = 19 | struct 20 | (* Import *) 21 | 22 | type 'a VIdMap = 'a IdsCore.VIdMap 23 | type 'a TyConMap = 'a IdsCore.TyConMap 24 | type 'a StrIdMap = 'a IdsCore.StrIdMap 25 | 26 | type IdStatus = IdStatus.IdStatus 27 | type TyVarSet = TyVarSet.set 28 | 29 | 30 | (* Types *) 31 | 32 | type ValStr = IdStatus 33 | type ValEnv = IdStatus VIdMap 34 | type TyStr = ValEnv 35 | type TyEnv = ValEnv TyConMap 36 | datatype Env = Env of StrEnv * TyEnv * ValEnv 37 | withtype StrEnv = Env StrIdMap 38 | 39 | type Context = TyVarSet * Env 40 | end; 41 | -------------------------------------------------------------------------------- /eval/SVal.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML special values 5 | * 6 | * Definition, Section 6.2 7 | *) 8 | 9 | structure SVal :> SVAL = 10 | struct 11 | (* Type [Section 6.2] *) 12 | 13 | datatype SVal = (* [sv] *) 14 | INT of LibrarySVal.IntSVal 15 | | WORD of LibrarySVal.WordSVal 16 | | STRING of LibrarySVal.StringSVal 17 | | CHAR of LibrarySVal.CharSVal 18 | | REAL of LibrarySVal.RealSVal 19 | 20 | 21 | (* Conversions *) 22 | 23 | fun toString(INT i) = LibrarySVal.intToString i 24 | | toString(WORD w) = "0wx" ^ LibrarySVal.wordToString w 25 | | toString(STRING s) = "\"" ^ LibrarySVal.stringToString s ^ "\"" 26 | | toString(CHAR c) = "#\"" ^ LibrarySVal.charToString c ^ "\"" 27 | | toString(REAL r) = LibrarySVal.realToString r 28 | 29 | (* Comparison *) 30 | 31 | fun compare(INT i1, INT i2) = LibrarySVal.compareInt(i1, i2) 32 | | compare(WORD w1, WORD w2) = LibrarySVal.compareWord(w1, w2) 33 | | compare(STRING s1, STRING s2) = LibrarySVal.compareString(s1, s2) 34 | | compare(CHAR c1, CHAR c2) = LibrarySVal.compareChar(c1, c2) 35 | | compare _ = raise Domain 36 | 37 | fun equal(sv1, sv2) = compare(sv1, sv2) = EQUAL 38 | end; 39 | -------------------------------------------------------------------------------- /basis/INTEGER-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library 5 | *) 6 | 7 | structure Int = struct type int = int end 8 | structure LargeInt = Int 9 | 10 | signature INTEGER = 11 | sig 12 | eqtype int 13 | val toLarge : int -> LargeInt.int 14 | val fromLarge : LargeInt.int -> int 15 | val toInt : int -> Int.int 16 | val fromInt : Int.int -> int 17 | val precision : Int.int option 18 | val minInt : int option 19 | val maxInt : int option 20 | val + : int * int -> int 21 | val - : int * int -> int 22 | val * : int * int -> int 23 | val div : int * int -> int 24 | val mod : int * int -> int 25 | val quot : int * int -> int 26 | val rem : int * int -> int 27 | val compare : int * int -> order 28 | val > : int * int -> bool 29 | val >= : int * int -> bool 30 | val < : int * int -> bool 31 | val <= : int * int -> bool 32 | val ~ : int -> int 33 | val abs : int -> int 34 | val min : int * int -> int 35 | val max : int * int -> int 36 | val sign : int -> Int.int 37 | val sameSign : int * int -> bool 38 | val fmt : StringCvt.radix -> int -> string 39 | val toString : int -> string 40 | val scan : StringCvt.radix -> (char, 'a) StringCvt.reader -> (int, 'a) StringCvt.reader 41 | val fromString : string -> int option 42 | end; 43 | -------------------------------------------------------------------------------- /basis/IMPERATIVE_IO-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library 5 | * 6 | * Note: Incomplete. 7 | *) 8 | 9 | signature IMPERATIVE_IO = 10 | sig 11 | structure StreamIO : STREAM_IO 12 | type vector = StreamIO.vector 13 | type elem = StreamIO.elem 14 | type instream 15 | type outstream 16 | val input : instream -> vector 17 | val input1 : instream -> elem option 18 | val inputN : instream * int -> vector 19 | val inputAll : instream -> vector 20 | (* 21 | val canInput : instream * int -> int option 22 | val lookahead : instream -> elem option 23 | *) 24 | val closeIn : instream -> unit 25 | val endOfStream : instream -> bool 26 | val output : outstream * vector -> unit 27 | val output1 : outstream * elem -> unit 28 | val flushOut : outstream -> unit 29 | val closeOut : outstream -> unit 30 | (* 31 | val mkInstream : StreamIO.instream -> instream 32 | val getInstream : instream -> StreamIO.instream 33 | val setInstream : instream * StreamIO.instream -> unit 34 | val mkOutstream : StreamIO.outstream -> outstream 35 | val getOutstream : outstream -> StreamIO.outstream 36 | val setOutstream : outstream * StreamIO.outstream -> unit 37 | val getPosOut : outstream -> StreamIO.out_pos 38 | val setPosOut : outstream * StreamIO.out_pos -> unit 39 | *) 40 | end; 41 | -------------------------------------------------------------------------------- /basis/StringCvt.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library 5 | *) 6 | 7 | structure StringCvt :> STRING_CVT = 8 | struct 9 | type cs = int 10 | type ('a,'b) reader = 'b -> ('a * 'b) option 11 | 12 | datatype radix = BIN | OCT | DEC | HEX 13 | datatype realfmt = 14 | SCI of int option 15 | | FIX of int option 16 | | GEN of int option 17 | | EXACT 18 | 19 | infix ^ 20 | val op^ = String.^ 21 | 22 | fun clamp i = if i < 0 then 0 else i 23 | fun padding c i = String.implode(List.tabulate(clamp i, fn _ => c)) 24 | fun padLeft c i s = padding c (i - String.size s) ^ s 25 | fun padRight c i s = s ^ padding c (i - String.size s) 26 | 27 | fun splitl p f src = splitl'(p, f, src, nil) 28 | and splitl'(p, f, src, cs) = 29 | case f src of 30 | NONE => 31 | (String.implode(List.rev cs), src) 32 | | SOME(c, src') => 33 | if p c then splitl'(p, f, src', c::cs) 34 | else (String.implode(List.rev cs), src) 35 | 36 | fun takel p f s = #1(splitl p f s) 37 | fun dropl p f s = #2(splitl p f s) 38 | fun skipWS f s = dropl Char.isSpace f s 39 | 40 | fun scanString f s = Option.map #1 (f (reader s) 0 : ('a * cs) option) 41 | and reader s i = SOME(String.sub(s, i), i + 1) handle Subscript => NONE 42 | end; 43 | -------------------------------------------------------------------------------- /lib/Makefile.depend.in: -------------------------------------------------------------------------------- 1 | # Library 2 | DYNAMIC_LIBRARY-sig.$(EXT) : ../eval/DynamicObjectsCore.$(EXT) 3 | DynamicLibrary.$(EXT) : DYNAMIC_LIBRARY-sig.$(EXT) ../elab/StaticObjectsCore.$(EXT) ../eval/DynamicObjectsCore.$(EXT) ../elab/StaticObjectsModule.$(EXT) ../eval/DynamicObjectsModule.$(EXT) ../syntax/IdsCore.$(EXT) ../syntax/IdStatus.$(EXT) ../syntax/IdsModule.$(EXT) ../eval/ExName.$(EXT) ../eval/State.$(EXT) ../eval/InitialDynamicBasis.$(EXT) ../eval/DynamicBasis.$(EXT) ../eval/SVal.$(EXT) ../eval/Val.$(EXT) Use.$(EXT) LibrarySVal.$(EXT) IdsLibrary.$(EXT) ../infrastructure/FinMapFn.$(EXT) 4 | IdsLibrary.$(EXT) : ../syntax/IdStatus.$(EXT) ../syntax/IdsCore.$(EXT) 5 | LIBRARY_SVAL-sig.$(EXT) : 6 | LibrarySVal.$(EXT) : LIBRARY_SVAL-sig.$(EXT) 7 | STATIC_LIBRARY-sig.$(EXT) : ../elab/StaticObjectsCore.$(EXT) ../elab/StaticObjectsModule.$(EXT) 8 | StaticLibrary.$(EXT) : STATIC_LIBRARY-sig.$(EXT) ../elab/StaticObjectsCore.$(EXT) ../elab/StaticObjectsModule.$(EXT) ../elab/TyName.$(EXT) ../elab/OverloadingClass.$(EXT) ../syntax/Lab.$(EXT) ../elab/Type.$(EXT) ../syntax/IdsCore.$(EXT) ../elab/TypeFcn.$(EXT) ../syntax/TyVar.$(EXT) ../elab/InitialStaticEnv.$(EXT) ../syntax/IdStatus.$(EXT) ../syntax/IdsModule.$(EXT) ../elab/StaticBasis.$(EXT) ../elab/InitialStaticBasis.$(EXT) LibrarySVal.$(EXT) IdsLibrary.$(EXT) 9 | USE-sig.$(EXT) : 10 | Use.$(EXT) : USE-sig.$(EXT) 11 | -------------------------------------------------------------------------------- /basis/STREAM_IO-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library 5 | * 6 | * Note: Incomplete. 7 | *) 8 | 9 | signature STREAM_IO = 10 | sig 11 | type elem 12 | type vector 13 | (* 14 | type instream 15 | type outstream 16 | type out_pos 17 | type reader 18 | type writer 19 | type pos 20 | val input : instream -> vector * instream 21 | val input1 : instream -> (elem * instream) option 22 | val inputN : instream * int -> vector * instream 23 | val inputAll : instream -> vector * instream 24 | val canInput : instream * int -> int option 25 | val closeIn : instream -> unit 26 | val endOfStream : instream -> bool 27 | val output : outstream * vector -> unit 28 | val output1 : outstream * elem -> unit 29 | val flushOut : outstream -> unit 30 | val closeOut : outstream -> unit 31 | val mkInstream : reader * vector -> instream 32 | val getReader : instream -> reader * vector 33 | val filePosIn : instream -> pos 34 | val setBufferMode : outstream * IO.buffer_mode -> unit 35 | val getBufferMode : outstream -> IO.buffer_mode 36 | val mkOutstream : writer * IO.buffer_mode -> outstream 37 | val getWriter : outstream -> writer * IO.buffer_mode 38 | val getPosOut : outstream -> out_pos 39 | val setPosOut : out_pos -> outstream 40 | val filePosOut : out_pos -> pos 41 | *) 42 | end; 43 | -------------------------------------------------------------------------------- /elab/TYNAME-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML type names 5 | * 6 | * Definition, Section 4.1 7 | * 8 | * Notes: 9 | * - Equality is not a boolean attribute. We distinguish a 3rd kind of special 10 | * type names which have equality regardless of the types applied. This 11 | * implements ref, array, and equivalent types. 12 | * - For easy checking of pattern exhaustiveness we add an attribute 13 | * `span' counting the number of constructors of the type. 14 | * - For checking of declaration orders etc we provide access to a time stamp. 15 | *) 16 | 17 | signature TYNAME = 18 | sig 19 | (* Type [Section 4.1] *) 20 | 21 | eqtype TyName (* [t] *) 22 | 23 | 24 | (* Operations *) 25 | 26 | val tyname : string * int * bool * int -> TyName 27 | val invent : int * bool -> TyName 28 | val rename : TyName -> TyName 29 | val Abs : TyName -> TyName 30 | 31 | val arity : TyName -> int 32 | val admitsEquality : TyName -> bool 33 | val span : TyName -> int 34 | val toString : TyName -> string 35 | val time : TyName -> Stamp.stamp 36 | 37 | val compare : TyName * TyName -> order 38 | 39 | val removeEquality : TyName -> unit 40 | val adjustSpan : TyName * int -> unit 41 | end; 42 | -------------------------------------------------------------------------------- /test/dec-strdec.sml: -------------------------------------------------------------------------------- 1 | (* dec-strdec.sml *) 2 | 3 | (* Checks parsing of decs as strdecs. *) 4 | 5 | (* 6 | HaMLet SML/NJ MosML MLton MLKit Poly/ML MLWorks Alice 7 | 1.2 110.52 2.01 041109 4.1.1 4.1.3 2.0 1.0 8 | 9 | A - + + + - + ? - 10 | B - - + + - + ? - 11 | C - - + + - + ? - 12 | B' - - + + - + ? - 13 | B'' - - - - - - ? - 14 | C' - - - - - - ? - 15 | 16 | Note that none of them has to be accepted, but B'' and C' must not be. 17 | *) 18 | 19 | (* A *) 20 | val x = 21 | let 22 | fun double x = x + x 23 | val y = double 2.0 24 | in () end; 25 | 26 | (* B *) 27 | structure X = 28 | struct 29 | fun double x = x + x 30 | val y = double 2.0 31 | end; 32 | 33 | (* C *) 34 | fun double x = x + x 35 | val y = double 2.0; 36 | 37 | (* B' *) 38 | structure X = 39 | struct 40 | fun double x = x + x; 41 | val y = double 2.0 42 | end; 43 | 44 | (* B'' *) 45 | structure X = 46 | struct 47 | fun double x = x + x 48 | structure X = struct end 49 | val y = double 2.0 50 | end; 51 | 52 | (* C' *) 53 | fun double x = x + x; 54 | val y = double 2.0; 55 | -------------------------------------------------------------------------------- /syntax/Annotation.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2013-2025 3 | * 4 | * Helpers for abstract syntax annotations 5 | *) 6 | 7 | structure Annotation : ANNOTATION = 8 | struct 9 | open Prop 10 | 11 | type 'a annotation = (Source.loc, 'a) cons (* [A] *) 12 | datatype ('a, 'b) phrase = @@ of 'a * 'b annotation 13 | 14 | infix @@ 15 | fun syntax(s@@A) = s 16 | fun annotation(s@@A) = A 17 | 18 | fun loc A = get(hd A) 19 | fun fromLoc l = let val A = new() in set(hd A, l); A end 20 | fun copy A = fromLoc(loc A) 21 | fun nowhere() = fromLoc Source.nowhere 22 | 23 | fun transform1 f (_@@A) = fromLoc(f(loc A)) 24 | fun transform2 f (_@@A1, _@@A2) = fromLoc(f(loc A1, loc A2)) 25 | 26 | fun at(phrase) = transform1 Source.at phrase 27 | fun left(phrase) = transform1 Source.left phrase 28 | fun right(phrase) = transform1 Source.right phrase 29 | fun over(phrase1, phrase2) = transform2 Source.over (phrase1, phrase2) 30 | 31 | fun overSome(phrase1, NONE) = at(phrase1) 32 | | overSome(phrase1, SOME phrase2) = over(phrase1, phrase2) 33 | 34 | fun overAll[] = raise Empty 35 | | overAll[phrase] = at(phrase) 36 | | overAll((phrase as x@@_)::phrases) = over(phrase, x@@overAll(phrases)) 37 | 38 | exception Annotation 39 | 40 | infix --> 41 | fun a --> p = (if has p then raise Annotation else set(p, a); a) 42 | end; 43 | -------------------------------------------------------------------------------- /basis/LIST-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library 5 | *) 6 | 7 | signature LIST = 8 | sig 9 | datatype list = datatype list 10 | exception Empty 11 | val null : 'a list -> bool 12 | val length : 'a list -> int 13 | val @ : 'a list * 'a list -> 'a list 14 | val hd : 'a list -> 'a 15 | val tl : 'a list -> 'a list 16 | val last : 'a list -> 'a 17 | val getItem : 'a list -> ('a * 'a list) option 18 | val nth : 'a list * int -> 'a 19 | val take : 'a list * int -> 'a list 20 | val drop : 'a list * int -> 'a list 21 | val rev : 'a list -> 'a list 22 | val concat : 'a list list -> 'a list 23 | val revAppend : 'a list * 'a list -> 'a list 24 | val app : ('a -> unit) -> 'a list -> unit 25 | val map : ('a -> 'b) -> 'a list -> 'b list 26 | val mapPartial : ('a -> 'b option) -> 'a list -> 'b list 27 | val find : ('a -> bool) -> 'a list -> 'a option 28 | val filter : ('a -> bool) -> 'a list -> 'a list 29 | val partition : ('a -> bool) -> 'a list -> 'a list * 'a list 30 | val foldl : ('a * 'b -> 'b) -> 'b -> 'a list -> 'b 31 | val foldr : ('a * 'b -> 'b) -> 'b -> 'a list -> 'b 32 | val exists : ('a -> bool) -> 'a list -> bool 33 | val all : ('a -> bool) -> 'a list -> bool 34 | val tabulate : int * (int -> 'a) -> 'a list 35 | val collate : ('a * 'a -> order) -> 'a list * 'a list -> order 36 | end; 37 | -------------------------------------------------------------------------------- /basis/MONO_VECTOR_SLICE-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2002-2025 3 | * 4 | * Standard ML Basis Library 5 | *) 6 | 7 | signature MONO_VECTOR_SLICE = 8 | sig 9 | type elem 10 | type vector 11 | type slice 12 | val length : slice -> int 13 | val sub : slice * int -> elem 14 | val full : vector -> slice 15 | val slice : vector * int * int option -> slice 16 | val subslice : slice * int * int option -> slice 17 | val base : slice -> vector * int * int 18 | val vector : slice -> vector 19 | val concat : slice list -> vector 20 | val isEmpty : slice -> bool 21 | val getItem : slice -> (elem * slice) option 22 | val appi : (int * elem -> unit) -> slice -> unit 23 | val app : (elem -> unit) -> slice -> unit 24 | val mapi : (int * elem -> elem) -> slice -> vector 25 | val map : (elem -> elem) -> slice -> vector 26 | val foldli : (int * elem * 'b -> 'b) -> 'b -> slice -> 'b 27 | val foldri : (int * elem * 'b -> 'b) -> 'b -> slice -> 'b 28 | val foldl : (elem * 'b -> 'b) -> 'b -> slice -> 'b 29 | val foldr : (elem * 'b -> 'b) -> 'b -> slice -> 'b 30 | val findi : (int * elem -> bool) -> slice -> (int * elem) option 31 | val find : (elem -> bool) -> slice -> elem option 32 | val exists : (elem -> bool) -> slice -> bool 33 | val all : (elem -> bool) -> slice -> bool 34 | val collate : (elem * elem -> order) -> slice * slice -> order 35 | end; 36 | -------------------------------------------------------------------------------- /basis/MONO_ARRAY-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library 5 | *) 6 | 7 | signature MONO_ARRAY = 8 | sig 9 | eqtype array 10 | type elem 11 | type vector 12 | val maxLen : int 13 | val array : int * elem -> array 14 | val fromList : elem list -> array 15 | val tabulate : int * (int -> elem) -> array 16 | val length : array -> int 17 | val sub : array * int -> elem 18 | val update : array * int * elem -> unit 19 | val vector : array -> vector 20 | val copy : {src : array, dst : array, di : int} -> unit 21 | val copyVec : {src : vector, dst : array, di : int} -> unit 22 | val appi : (int * elem -> unit) -> array -> unit 23 | val app : (elem -> unit) -> array -> unit 24 | val modifyi : (int * elem -> elem) -> array -> unit 25 | val modify : (elem -> elem) -> array -> unit 26 | val foldli : (int * elem * 'b -> 'b) -> 'b -> array -> 'b 27 | val foldri : (int * elem * 'b -> 'b) -> 'b -> array -> 'b 28 | val foldl : (elem * 'b -> 'b) -> 'b -> array -> 'b 29 | val foldr : (elem * 'b -> 'b) -> 'b -> array -> 'b 30 | val findi : (int * elem -> bool) -> array -> (int * elem) option 31 | val find : (elem -> bool) -> array -> elem option 32 | val exists : (elem -> bool) -> array -> bool 33 | val all : (elem -> bool) -> array -> bool 34 | val collate : (elem * elem -> order) -> array * array -> order 35 | end; 36 | -------------------------------------------------------------------------------- /elab/STATIC_ENV-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML environments of the static semantics of the core 5 | * 6 | * Definition, Sections 4.2, 4.3, 4.8, 4.9, and 5.5 7 | * 8 | * Notes: see StaticObjectsCore.sml 9 | *) 10 | 11 | signature STATIC_ENV = 12 | sig 13 | (* Inheritance *) 14 | 15 | include GENERIC_ENV 16 | where type Env = StaticObjectsCore.Env 17 | and type ValStr = StaticObjectsCore.ValStr 18 | and type TyStr = StaticObjectsCore.TyStr 19 | 20 | 21 | (* Import *) 22 | 23 | type TyNameSet = StaticObjectsCore.TyNameSet 24 | type TyVarSet = StaticObjectsCore.TyVarSet 25 | type Realisation = Type.Realisation 26 | 27 | 28 | (* Operations *) 29 | 30 | val tyvars : Env -> TyVarSet 31 | val tyvarsVE : ValEnv -> TyVarSet 32 | val tynames : Env -> TyNameSet 33 | val tynamesVE : ValEnv -> TyNameSet 34 | val tynamesTE : TyEnv -> TyNameSet 35 | val tynamesSE : StrEnv -> TyNameSet 36 | val undetermined : Env -> bool StampMap.map 37 | 38 | val isWellFormed : Env -> bool 39 | 40 | val Clos : ValEnv -> ValEnv 41 | val Abs : TyEnv * Env -> Env 42 | val realise : Realisation -> Env -> Env 43 | 44 | val enriches : Env * Env -> bool 45 | val equalsVE : ValEnv * ValEnv -> bool 46 | 47 | val maximiseEquality : TyEnv -> unit 48 | end; 49 | -------------------------------------------------------------------------------- /parse/BINDING_CONTEXT-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML context for binding analysis 5 | *) 6 | 7 | signature BINDING_CONTEXT = 8 | sig 9 | (* Import *) 10 | 11 | type VId = IdsCore.VId 12 | type TyCon = IdsCore.TyCon 13 | type StrId = IdsCore.StrId 14 | type longVId = IdsCore.longVId 15 | type longTyCon = IdsCore.longTyCon 16 | type longStrId = IdsCore.longStrId 17 | 18 | type TyVarSet = BindingObjectsCore.TyVarSet 19 | type TyStr = BindingObjectsCore.TyStr 20 | type TyEnv = BindingObjectsCore.TyEnv 21 | type ValStr = BindingObjectsCore.ValStr 22 | type ValEnv = BindingObjectsCore.ValEnv 23 | type Env = BindingObjectsCore.Env 24 | type Context = BindingObjectsCore.Context 25 | 26 | 27 | (* Operations *) 28 | 29 | val Uof : Context -> TyVarSet 30 | val Eof : Context -> Env 31 | 32 | val plusU : Context * TyVarSet -> Context 33 | val plusE : Context * Env -> Context 34 | val plusVE : Context * ValEnv -> Context 35 | val plusTE : Context * TyEnv -> Context 36 | val plusVEandTE : Context * (ValEnv * TyEnv) -> Context 37 | 38 | val findLongVId : Context * longVId -> ValStr option 39 | val findLongTyCon : Context * longTyCon -> TyStr option 40 | val findLongStrId : Context * longStrId -> Env option 41 | end; 42 | -------------------------------------------------------------------------------- /elab/TYPEFCN-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML type functions 5 | * 6 | * Definition, Section 4.2, 4.4, and 4.8 7 | * 8 | * Note: 9 | * Application copies the type (except free type variables). 10 | *) 11 | 12 | signature TYPEFCN = 13 | sig 14 | (* Import *) 15 | 16 | type Type = StaticObjectsCore.Type 17 | type TypeFcn = StaticObjectsCore.TypeFcn 18 | type TyVar = StaticObjectsCore.TyVar 19 | type TyName = StaticObjectsCore.TyName 20 | type TyVarSet = StaticObjectsCore.TyVarSet 21 | type TyNameSet = StaticObjectsCore.TyNameSet 22 | type Realisation = Type.Realisation 23 | 24 | 25 | (* Operations *) 26 | 27 | val fromTyName : TyName -> TypeFcn 28 | val toTyName : TypeFcn -> TyName (* raises Type.Type *) 29 | val isTyName : TypeFcn -> bool 30 | 31 | val arity : TypeFcn -> int 32 | val admitsEquality : TypeFcn -> bool 33 | 34 | val tyvars : TypeFcn -> TyVarSet 35 | val tynames : TypeFcn -> TyNameSet 36 | val undetermined : TypeFcn -> bool StampMap.map 37 | val normalise : TypeFcn -> TypeFcn 38 | val rename : TypeFcn -> TypeFcn 39 | 40 | val equals : TypeFcn * TypeFcn -> bool 41 | 42 | exception Apply 43 | val apply : Type list * TypeFcn -> Type (* raises Apply *) 44 | 45 | val realise : Realisation -> TypeFcn -> TypeFcn 46 | end; 47 | -------------------------------------------------------------------------------- /infrastructure/PPMisc.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML miscellaneous pretty printing helpers 5 | *) 6 | 7 | structure PPMisc : PP_MISC = 8 | struct 9 | (* Import *) 10 | 11 | open PrettyPrint 12 | 13 | infixr ^^ ^/^ 14 | 15 | 16 | (* Some PP combinators *) 17 | 18 | val nest = nest 2 19 | 20 | fun paren doc = text "(" ^^ fbox(below doc) ^^ text ")" 21 | fun brace doc = text "{" ^^ fbox(below doc) ^^ text "}" 22 | fun brack doc = text "[" ^^ fbox(below doc) ^^ text "]" 23 | fun comment doc = text "(* " ^^ fbox(below doc) ^^ text " *)" 24 | 25 | fun parenAt p (p', doc) = if p' > p then paren doc else doc 26 | 27 | fun ppList ppX [] = empty 28 | | ppList ppX (x::xs) = ppX x ^/^ ppList ppX xs 29 | 30 | fun ppCommaList ppX [] = empty 31 | | ppCommaList ppX [x] = ppX x 32 | | ppCommaList ppX (x::xs) = ppX x ^^ text "," ^/^ ppCommaList ppX xs 33 | 34 | fun ppStarList ppX [] = empty 35 | | ppStarList ppX [x] = ppX x 36 | | ppStarList ppX (x::xs) = hbox(ppX x ^/^ text "*") ^/^ ppStarList ppX xs 37 | 38 | fun ppSeqPrec ppXPrec n [] = empty 39 | | ppSeqPrec ppXPrec n [x] = ppXPrec n x 40 | | ppSeqPrec ppXPrec n xs = paren(ppCommaList (ppXPrec 0) xs) 41 | 42 | fun ppSeq ppX = ppSeqPrec (fn _ => ppX) 0 43 | end; 44 | -------------------------------------------------------------------------------- /basis/ARRAY-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library 5 | *) 6 | 7 | signature ARRAY = 8 | sig 9 | type 'a array (*= 'a array*) 10 | type 'a vector = 'a Vector.vector 11 | val maxLen : int 12 | val array : int * 'a -> 'a array 13 | val fromList : 'a list -> 'a array 14 | val tabulate : int * (int -> 'a) -> 'a array 15 | val length : 'a array -> int 16 | val sub : 'a array * int -> 'a 17 | val update : 'a array * int * 'a -> unit 18 | val vector : 'a array -> 'a vector 19 | val copy : {src : 'a array, dst : 'a array, di : int} -> unit 20 | val copyVec : {src : 'a vector, dst : 'a array, di : int} -> unit 21 | val appi : (int * 'a -> unit) -> 'a array -> unit 22 | val app : ('a -> unit) -> 'a array -> unit 23 | val modifyi : (int * 'a -> 'a) -> 'a array -> unit 24 | val modify : ('a -> 'a) -> 'a array -> unit 25 | val foldli : (int * 'a * 'b -> 'b) -> 'b -> 'a array -> 'b 26 | val foldri : (int * 'a * 'b -> 'b) -> 'b -> 'a array -> 'b 27 | val foldl : ('a * 'b -> 'b) -> 'b -> 'a array -> 'b 28 | val foldr : ('a * 'b -> 'b) -> 'b -> 'a array -> 'b 29 | val findi : (int * 'a -> bool) -> 'a array -> (int * 'a) option 30 | val find : ('a -> bool) -> 'a array -> 'a option 31 | val exists : ('a -> bool) -> 'a array -> bool 32 | val all : ('a -> bool) -> 'a array -> bool 33 | val collate : ('a * 'a -> order) -> 'a array * 'a array -> order 34 | end; 35 | -------------------------------------------------------------------------------- /basis/OS_PATH-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library 5 | *) 6 | 7 | signature OS_PATH = 8 | sig 9 | exception Path 10 | exception InvalidArc 11 | val parentArc : string 12 | val currentArc : string 13 | val validVolume : {isAbs : bool, vol : string} -> bool 14 | val fromString : string -> {isAbs : bool, vol : string, arcs : string list} 15 | val toString : {isAbs : bool, vol : string, arcs : string list} -> string 16 | val getVolume : string -> string 17 | val getParent : string -> string 18 | val splitDirFile : string -> {dir : string, file : string} 19 | val joinDirFile : {dir : string, file : string} -> string 20 | val dir : string -> string 21 | val file : string -> string 22 | val splitBaseExt : string -> {base : string, ext : string option} 23 | val joinBaseExt : {base : string, ext : string option} -> string 24 | val base : string -> string 25 | val ext : string -> string option 26 | val mkCanonical : string -> string 27 | val isCanonical : string -> bool 28 | val mkAbsolute : {path : string, relativeTo : string} -> string 29 | val mkRelative : {path : string, relativeTo : string} -> string 30 | val isAbsolute : string -> bool 31 | val isRelative : string -> bool 32 | val isRoot : string -> bool 33 | val concat : string * string -> string 34 | val fromUnixPath : string -> string 35 | val toUnixPath : string -> string 36 | end; 37 | -------------------------------------------------------------------------------- /basis/VECTOR_SLICE-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2002-2025 3 | * 4 | * Standard ML Basis Library 5 | *) 6 | 7 | signature VECTOR_SLICE = 8 | sig 9 | type 'a slice 10 | val length : 'a slice -> int 11 | val sub : 'a slice * int -> 'a 12 | val full : 'a Vector.vector -> 'a slice 13 | val slice : 'a Vector.vector * int * int option -> 'a slice 14 | val subslice : 'a slice * int * int option -> 'a slice 15 | val base : 'a slice -> 'a Vector.vector * int * int 16 | val vector : 'a slice -> 'a Vector.vector 17 | val concat : 'a slice list -> 'a Vector.vector 18 | val isEmpty : 'a slice -> bool 19 | val getItem : 'a slice -> ('a * 'a slice) option 20 | val appi : (int * 'a -> unit) -> 'a slice -> unit 21 | val app : ('a -> unit) -> 'a slice -> unit 22 | val mapi : (int * 'a -> 'b) -> 'a slice -> 'b vector 23 | val map : ('a -> 'b) -> 'a slice -> 'b vector 24 | val foldli : (int * 'a * 'b -> 'b) -> 'b -> 'a slice -> 'b 25 | val foldri : (int * 'a * 'b -> 'b) -> 'b -> 'a slice -> 'b 26 | val foldl : ('a * 'b -> 'b) -> 'b -> 'a slice -> 'b 27 | val foldr : ('a * 'b -> 'b) -> 'b -> 'a slice -> 'b 28 | val findi : (int * 'a -> bool) -> 'a slice -> (int * 'a) option 29 | val find : ('a -> bool) -> 'a slice -> 'a option 30 | val exists : ('a -> bool) -> 'a slice -> bool 31 | val all : ('a -> bool) -> 'a slice -> bool 32 | val collate : ('a * 'a -> order) -> 'a slice * 'a slice -> order 33 | end; 34 | -------------------------------------------------------------------------------- /exec/Makefile.depend.in: -------------------------------------------------------------------------------- 1 | # Execution 2 | BASIS-sig.$(EXT) : ../elab/StaticObjectsModule.$(EXT) ../eval/DynamicObjectsModule.$(EXT) 3 | Basis.$(EXT) : BASIS-sig.$(EXT) ../elab/StaticObjectsModule.$(EXT) ../eval/DynamicObjectsModule.$(EXT) ../elab/StaticBasis.$(EXT) ../eval/DynamicBasis.$(EXT) 4 | PPBasis.$(EXT) : PP_BASIS-sig.$(EXT) ../eval/DynamicObjectsCore.$(EXT) Basis.$(EXT) PPEnv.$(EXT) ../infrastructure/PrettyPrint.$(EXT) ../elab/PPStaticBasis.$(EXT) 5 | PPEnv.$(EXT) : PP_ENV-sig.$(EXT) ../elab/StaticObjectsCore.$(EXT) ../eval/DynamicObjectsCore.$(EXT) ../infrastructure/PrettyPrint.$(EXT) ../infrastructure/PPMisc.$(EXT) ../syntax/IdsCore.$(EXT) ../syntax/IdStatus.$(EXT) ../eval/PPVal.$(EXT) ../elab/PPType.$(EXT) ../elab/PPStaticEnv.$(EXT) ../elab/TyName.$(EXT) 6 | PP_BASIS-sig.$(EXT) : ../infrastructure/PrettyPrint.$(EXT) ../eval/DynamicObjectsCore.$(EXT) Basis.$(EXT) 7 | PP_ENV-sig.$(EXT) : ../infrastructure/PrettyPrint.$(EXT) ../elab/StaticObjectsCore.$(EXT) ../eval/DynamicObjectsCore.$(EXT) 8 | PROGRAM-sig.$(EXT) : ../syntax/Syntax.$(EXT) Basis.$(EXT) ../eval/State.$(EXT) 9 | Program.$(EXT) : PROGRAM-sig.$(EXT) ../eval/DynamicObjectsCore.$(EXT) ../elab/StaticBasis.$(EXT) ../eval/DynamicBasis.$(EXT) Basis.$(EXT) ../eval/EvalModule.$(EXT) ../syntax/Syntax.$(EXT) ../infrastructure/PrettyPrint.$(EXT) ../eval/PPVal.$(EXT) ../elab/PPStaticBasis.$(EXT) ../eval/PPDynamicBasis.$(EXT) PPBasis.$(EXT) ../elab/ElabModule.$(EXT) ../infrastructure/Error.$(EXT) 10 | -------------------------------------------------------------------------------- /syntax/LongIdFn.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML long identifiers 5 | * 6 | * Definition, Section 2.4 7 | * 8 | * Note: 9 | * This is a generic functor that generates a long identifier type from a 10 | * given identifier type and the StrId type. 11 | *) 12 | 13 | functor LongIdFn( 14 | structure Id : ID 15 | structure StrId : ID 16 | ) :> LONGID 17 | where type Id.Id = Id.Id 18 | and type StrId.Id = StrId.Id 19 | = 20 | struct 21 | (* Import *) 22 | 23 | structure Id = Id 24 | structure StrId = StrId 25 | 26 | type Id = Id.Id 27 | type StrId = StrId.Id 28 | 29 | 30 | (* Type [Section 2.4] *) 31 | 32 | type longId = StrId list * Id (* [longid] *) 33 | 34 | 35 | (* Conversions *) 36 | 37 | fun toId(strid, id) = id 38 | fun fromId id = ([], id) 39 | fun invent() = ([], Id.invent()) 40 | 41 | fun toString(strids, id) = 42 | let 43 | fun prefix [] = Id.toString id 44 | | prefix(id::ids) = StrId.toString id ^ "." ^ prefix ids 45 | in 46 | prefix strids 47 | end 48 | 49 | fun strengthen(strid, (strids, id)) = (strid::strids, id) 50 | 51 | fun implode longid = longid 52 | fun explode longid = longid 53 | 54 | fun isShort (strids, id) = List.null strids 55 | 56 | 57 | (* Ordering *) 58 | 59 | fun compare(longid1, longid2) = 60 | String.compare(toString longid1, toString longid2) 61 | end; 62 | -------------------------------------------------------------------------------- /doc/announce/announcement2.0.txt: -------------------------------------------------------------------------------- 1 | After this long time, I am pleased to announce the release of version 2.0 of HaMLet. This is the first public release since 2008. 2 | 3 | HaMLet is a faithful and complete implementation of the Standard ML programming language (SML'97) that aims to be 4 | 5 | - an accurate reference implementation of the language specification, 6 | - a platform for experimentation with the language semantics, 7 | - a useful tool for educational purposes. 8 | 9 | The HaMLet sources are intended to be as direct a translation of the language formalisation as possible. Even program evaluation is performed by a direct implementation of the rules of the dynamic semantics. The source code follows the structure of the SML Definition and is heavily cross-referenced. 10 | 11 | HaMLet can perform different phases of execution - like parsing, type checking, and evaluation - selectively. In particular, it is possible to execute programs in an untyped manner, thus exploring the universe where even ML programs "can go wrong". 12 | 13 | Version 2.0 brings a revamp of the internal AST representation. In particular, elaboration now stores its results in the AST, which should make HaMLet more useful as an experimental compiler front-end. As a proof of concept, the release integrates a simple compiler to JavaScript. 14 | 15 | For download, a complete list of changes, and more information, please visit the HaMLet homepage: 16 | 17 | http://mpi-sws.org/~rossberg/hamlet/ 18 | -------------------------------------------------------------------------------- /lib/IdsLibrary.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2013-2025 3 | * 4 | * Standard ML Basis Library identifiers 5 | *) 6 | 7 | structure IdsLibrary = 8 | struct 9 | (* Structure, type, exception and value identifiers *) 10 | 11 | val e = IdStatus.e 12 | val v = IdStatus.v 13 | 14 | val stridIO = StrId.fromString "IO" 15 | val stridWord8 = StrId.fromString "Word8" 16 | val tyconWord8 = TyCon.fromString "word" 17 | val tyconVector = TyCon.fromString "vector" 18 | 19 | val vid_Chr = VId.fromString "Chr" 20 | val vid_Div = VId.fromString "Div" 21 | val vid_Domain = VId.fromString "Domain" 22 | val vid_Overflow = VId.fromString "Overflow" 23 | val vid_Size = VId.fromString "Size" 24 | val vid_Subscript = VId.fromString "Subscript" 25 | val vid_Io = VId.fromString "Io" 26 | val vid_SysErr = VId.fromString "SysErr" 27 | 28 | val vidAbs = VId.fromString "abs" 29 | val vidNeg = VId.fromString "~" 30 | val vidPlus = VId.fromString "+" 31 | val vidMinus = VId.fromString "-" 32 | val vidTimes = VId.fromString "*" 33 | val vidDiv = VId.fromString "div" 34 | val vidMod = VId.fromString "mod" 35 | val vidBy = VId.fromString "/" 36 | val vidLess = VId.fromString "<" 37 | val vidGreater = VId.fromString ">" 38 | val vidLessEq = VId.fromString "<=" 39 | val vidGreaterEq = VId.fromString ">=" 40 | 41 | val vidUse = VId.fromString "use" 42 | end; 43 | -------------------------------------------------------------------------------- /basis/STRING-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library 5 | * 6 | * Note: Incomplete. 7 | *) 8 | 9 | signature STRING = 10 | sig 11 | eqtype string 12 | eqtype char 13 | val maxSize : int 14 | val size : string -> int 15 | val sub : string * int -> char 16 | val extract : string * int * int option -> string 17 | val substring : string * int * int -> string 18 | val ^ : string * string -> string 19 | val concat : string list -> string 20 | val concatWith : string -> string list -> string 21 | val str : char -> string 22 | val implode : char list -> string 23 | val explode : string -> char list 24 | val map : (char -> char) -> string -> string 25 | val translate : (char -> string) -> string -> string 26 | val tokens : (char -> bool) -> string -> string list 27 | val fields : (char -> bool) -> string -> string list 28 | val isPrefix : string -> string -> bool 29 | val isSubstring : string -> string -> bool 30 | val isSuffix : string -> string -> bool 31 | val compare : string * string -> order 32 | val collate : (char * char -> order) -> string * string -> order 33 | val < : string * string -> bool 34 | val <= : string * string -> bool 35 | val > : string * string -> bool 36 | val >= : string * string -> bool 37 | val fromString : String.string -> string option 38 | val toString : string -> String.string 39 | (* 40 | val fromCString : String.string -> string option 41 | *) 42 | val toCString : string -> String.string 43 | end; 44 | -------------------------------------------------------------------------------- /elab/TYPESCHEME-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML type schemes 5 | * 6 | * Definition, Section 4.2, 4.5, and 4.8 7 | * 8 | * Note: 9 | * Instantiation copies a type (except free type variables). 10 | * Closure does not! 11 | *) 12 | 13 | signature TYPESCHEME = 14 | sig 15 | (* Import *) 16 | 17 | type Type = StaticObjectsCore.Type 18 | type TypeScheme = StaticObjectsCore.TypeScheme 19 | type TyVar = StaticObjectsCore.TyVar 20 | type TyName = StaticObjectsCore.TyName 21 | type TyVarSet = StaticObjectsCore.TyVarSet 22 | type TyNameSet = StaticObjectsCore.TyNameSet 23 | 24 | type Substitution = Type.Substitution 25 | type Realisation = Type.Realisation 26 | type 'a TyNameMap = 'a TyNameMap.map 27 | 28 | 29 | (* Operations *) 30 | 31 | val instance : TypeScheme -> Type list * Type 32 | val Clos : Type -> TypeScheme 33 | val ClosRestricted : TyVarSet -> Type -> TypeScheme 34 | val isClosed : TypeScheme -> bool 35 | 36 | val tyvars : TypeScheme -> TyVarSet 37 | val tynames : TypeScheme -> TyNameSet 38 | val undetermined : TypeScheme -> bool StampMap.map 39 | val normalise : TypeScheme -> TypeScheme 40 | 41 | val generalises : TypeScheme * TypeScheme -> bool 42 | val equals : TypeScheme * TypeScheme -> bool 43 | 44 | val substitute : Substitution -> TypeScheme -> TypeScheme 45 | val realise : Realisation -> TypeScheme -> TypeScheme 46 | end; 47 | -------------------------------------------------------------------------------- /parse/BINDING_BASIS-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML environment for binding analysis 5 | *) 6 | 7 | signature BINDING_BASIS = 8 | sig 9 | (* Import *) 10 | 11 | type StrId = IdsCore.StrId 12 | type SigId = IdsModule.SigId 13 | type FunId = IdsModule.FunId 14 | type longStrId = IdsCore.longStrId 15 | type longTyCon = IdsCore.longTyCon 16 | 17 | type Env = BindingObjectsCore.Env 18 | type ValEnv = BindingObjectsCore.ValEnv 19 | type StrEnv = BindingObjectsCore.StrEnv 20 | type Context = BindingObjectsCore.Context 21 | type SigEnv = BindingObjectsModule.SigEnv 22 | type FunEnv = BindingObjectsModule.FunEnv 23 | type Basis = BindingObjectsModule.Basis 24 | 25 | 26 | (* Operations *) 27 | 28 | val empty : Basis 29 | val fromE : Env -> Basis 30 | val fromF : FunEnv -> Basis 31 | val fromG : SigEnv -> Basis 32 | 33 | val Cof : Basis -> Context 34 | 35 | val plus : Basis * Basis -> Basis 36 | val plusSE : Basis * StrEnv -> Basis 37 | val plusG : Basis * SigEnv -> Basis 38 | val plusF : Basis * FunEnv -> Basis 39 | val plusE : Basis * Env -> Basis 40 | 41 | val findStrId : Basis * StrId -> Env option 42 | val findSigId : Basis * SigId -> Env option 43 | val findFunId : Basis * FunId -> Env option 44 | val findLongStrId : Basis * longStrId -> Env option 45 | val findLongTyCon : Basis * longTyCon -> ValEnv option 46 | end; 47 | -------------------------------------------------------------------------------- /doc/INSTALL.txt: -------------------------------------------------------------------------------- 1 | To build a stand-alone HaMLet program under Unix-like systems, 2 | invoke one of the following commands: 3 | 4 | make with-alice (for Alice ML 1.4+) 5 | make with-mlkit (for ML Kit 4.3+) 6 | make with-mlton (for MLton 20010706+) 7 | make with-mosml (for Moscow ML 2.0+) 8 | make with-poly (for Poly/ML 5.0+) 9 | make with-smlnj (for SML/NJ 110+) 10 | make with-smlsharp (for SML# 0.20+) 11 | 12 | depending on what SML system you want to compile with. 13 | This will produce an executable named "hamlet". 14 | (For Moscow ML versions prior to 2.10 you will need to patch the definition of FIXES_mosml as indicated in the Makefile.) 15 | 16 | Alternatively, you can invoke 17 | 18 | use "hamlet.sml"; 19 | 20 | from an interactive SML prompt, which employs SML's `use' function. 21 | As yet another possibility, a single file containing all modules can be 22 | generated with 23 | 24 | make hamlet-bundle.sml 25 | 26 | for easy compilation with systems not supporting any of the above options. 27 | 28 | To compile under DOS-based systems you can either use the simple-minded 29 | "make.bat" batch file that fakes the commands above, or you install some 30 | `make' substitute (e.g. via Cygwin) and patch the Makefile according to 31 | the contained comments. [Note: make.bat is currently broken.] 32 | 33 | Under Unixes, you have the option of installing HaMLet: 34 | 35 | make INSTALLDIR=mypath install 36 | 37 | The default for mypath is /usr/local/hamlet. 38 | 39 | Please see the documentation in directory doc for more details. 40 | -------------------------------------------------------------------------------- /basis/MONO_ARRAY_SLICE-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2002-2025 3 | * 4 | * Standard ML Basis Library 5 | *) 6 | 7 | signature MONO_ARRAY_SLICE = 8 | sig 9 | type elem 10 | type array 11 | type slice 12 | type vector 13 | type vector_slice 14 | val length : slice -> int 15 | val sub : slice * int -> elem 16 | val update : slice * int * elem -> unit 17 | val full : array -> slice 18 | val slice : array * int * int option -> slice 19 | val subslice : slice * int * int option -> slice 20 | val base : slice -> array * int * int 21 | val vector : slice -> vector 22 | val copy : {src : slice, dst : array, di : int} -> unit 23 | val copyVec : {src : vector_slice, dst : array, di : int} -> unit 24 | val isEmpty : slice -> bool 25 | val getItem : slice -> (elem * slice) option 26 | val appi : (int * elem -> unit) -> slice -> unit 27 | val app : (elem -> unit) -> slice -> unit 28 | val modifyi : (int * elem -> elem) -> slice -> unit 29 | val modify : (elem -> elem) -> slice -> unit 30 | val foldli : (int * elem * 'b -> 'b) -> 'b -> slice -> 'b 31 | val foldri : (int * elem * 'b -> 'b) -> 'b -> slice -> 'b 32 | val foldl : (elem * 'b -> 'b) -> 'b -> slice -> 'b 33 | val foldr : (elem * 'b -> 'b) -> 'b -> slice -> 'b 34 | val findi : (int * elem -> bool) -> slice -> (int * elem) option 35 | val find : (elem -> bool) -> slice -> elem option 36 | val exists : (elem -> bool) -> slice -> bool 37 | val all : (elem -> bool) -> slice -> bool 38 | val collate : (elem * elem -> order) -> slice * slice -> order 39 | end; 40 | -------------------------------------------------------------------------------- /elab/CHECK_PATTERN-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML consistency of patterns and matches 5 | * 6 | * Definition, Section 4.11 7 | * 8 | * Note: 9 | * The requirement to check for irredundancy of matches is a `bug' in the 10 | * Definition since it cannot be checked in general, for two reasons: 11 | * 12 | * (1) There may be (hidden) aliasing of exception constructors. 13 | * Consequently, we only detect redundant exception constructors 14 | * if they are denoted by the same longvid. 15 | * 16 | * (2) There is no requirement of consistency for constructors in 17 | * sharing specifications or type realisations (actually, we 18 | * consider that a serious bug). For example, 19 | * datatype t1 = A | B 20 | * datatype t2 = C 21 | * sharing type t1 = t2 22 | * is a legal specification. This allows a mix of the constructors 23 | * to appear in matches, rendering the terms of irredundancy and 24 | * exhaustiveness meaningless. We make no attempt to detect this, 25 | * so generated warnings may or may not make sense in that situation. 26 | *) 27 | 28 | signature CHECK_PATTERN = 29 | sig 30 | (* Import *) 31 | 32 | type Pat = SyntaxCore.Pat 33 | type Match = SyntaxCore.Match 34 | 35 | type Env = StaticEnv.Env 36 | type Exhaustive = StaticObjectsCore.Exhaustive 37 | 38 | 39 | (* Operations *) 40 | 41 | val checkPat : Env * Pat -> Exhaustive 42 | val checkMatch : Env * Match -> Exhaustive 43 | end; 44 | -------------------------------------------------------------------------------- /eval/DynamicObjectsModule.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML objects of the dynamic semantics of modules 5 | * 6 | * Definition, Section 7.2 7 | *) 8 | 9 | structure DynamicObjectsModule = 10 | struct 11 | (* Import *) 12 | 13 | type StrId = IdsCore.StrId 14 | type 'a VIdMap = 'a IdsCore.VIdMap 15 | type 'a TyConMap = 'a IdsCore.TyConMap 16 | type 'a StrIdMap = 'a IdsCore.StrIdMap 17 | type 'a SigIdMap = 'a IdsModule.SigIdMap 18 | type 'a FunIdMap = 'a IdsModule.FunIdMap 19 | 20 | type IdStatus = DynamicObjectsCore.IdStatus 21 | type Env = DynamicObjectsCore.Env 22 | 23 | type StrExp = SyntaxModule.StrExp 24 | 25 | 26 | (* Compound objects [Section 7.2] *) 27 | 28 | datatype Int = Int of StrInt * TyInt * ValInt (* [I] *) 29 | withtype 30 | StrInt = Int StrIdMap (* [SI] *) 31 | and TyInt = (IdStatus VIdMap) TyConMap (* [TI] *) 32 | and ValInt = IdStatus VIdMap (* [VI] *) 33 | 34 | datatype FunctorClosure = 35 | FunctorClosure of (StrId * Int) * StrExp * (FunEnv * SigEnv * Env) 36 | withtype 37 | SigEnv = Int SigIdMap (* [G] *) 38 | and FunEnv = FunctorClosure FunIdMap (* [F] *) 39 | 40 | type Basis = FunEnv * SigEnv * Env (* [B] *) 41 | type IntBasis = SigEnv * Int (* [IB] *) 42 | end; 43 | -------------------------------------------------------------------------------- /basis/ARRAY_SLICE-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2002-2025 3 | * 4 | * Standard ML Basis Library 5 | *) 6 | 7 | signature ARRAY_SLICE = 8 | sig 9 | type 'a slice 10 | val length : 'a slice -> int 11 | val sub : 'a slice * int -> 'a 12 | val update : 'a slice * int * 'a -> unit 13 | val slice : 'a Array.array * int * int option -> 'a slice 14 | val full : 'a Array.array -> 'a slice 15 | val subslice : 'a slice * int * int option -> 'a slice 16 | val base : 'a slice -> 'a Array.array * int * int 17 | val vector : 'a slice -> 'a vector 18 | val copy : {src : 'a slice, dst : 'a Array.array, di : int} -> unit 19 | val copyVec : {src : 'a VectorSlice.slice, dst : 'a Array.array, di : int} -> unit 20 | val isEmpty : 'a slice -> bool 21 | val getItem : 'a slice -> ('a * 'a slice) option 22 | val appi : (int * 'a -> unit) -> 'a slice -> unit 23 | val app : ('a -> unit) -> 'a slice -> unit 24 | val modifyi : (int * 'a -> 'a) -> 'a slice -> unit 25 | val modify : ('a -> 'a) -> 'a slice -> unit 26 | val foldli : (int * 'a * 'b -> 'b) -> 'b -> 'a slice -> 'b 27 | val foldri : (int * 'a * 'b -> 'b) -> 'b -> 'a slice -> 'b 28 | val foldl : ('a * 'b -> 'b) -> 'b -> 'a slice -> 'b 29 | val foldr : ('a * 'b -> 'b) -> 'b -> 'a slice -> 'b 30 | val findi : (int * 'a -> bool) -> 'a slice -> (int * 'a) option 31 | val find : ('a -> bool) -> 'a slice -> 'a option 32 | val exists : ('a -> bool) -> 'a slice -> bool 33 | val all : ('a -> bool) -> 'a slice -> bool 34 | val collate : ('a * 'a -> order) -> 'a slice * 'a slice -> order 35 | end; 36 | -------------------------------------------------------------------------------- /basis/CHAR-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 2001-2025 3 | * 4 | * Standard ML Basis Library 5 | *) 6 | 7 | structure Char = struct type char = char end 8 | structure String = struct type string = string end 9 | structure StringCvt = struct type ('a, 'b) reader = 'b -> ('a * 'b) option end 10 | 11 | signature CHAR = 12 | sig 13 | eqtype char 14 | eqtype string 15 | val minChar : char 16 | val maxChar : char 17 | val maxOrd : int 18 | val ord : char -> int 19 | val chr : int -> char 20 | val succ : char -> char 21 | val pred : char -> char 22 | val < : char * char -> bool 23 | val <= : char * char -> bool 24 | val > : char * char -> bool 25 | val >= : char * char -> bool 26 | val compare : char * char -> order 27 | val contains : string -> char -> bool 28 | val notContains : string -> char -> bool 29 | val toLower : char -> char 30 | val toUpper : char -> char 31 | val isAlpha : char -> bool 32 | val isAlphaNum : char -> bool 33 | val isAscii : char -> bool 34 | val isCntrl : char -> bool 35 | val isDigit : char -> bool 36 | val isGraph : char -> bool 37 | val isHexDigit : char -> bool 38 | val isLower : char -> bool 39 | val isPrint : char -> bool 40 | val isSpace : char -> bool 41 | val isPunct : char -> bool 42 | val isUpper : char -> bool 43 | val fromString : String.string -> char option 44 | val scan : (Char.char, 'a) StringCvt.reader -> (char, 'a) StringCvt.reader 45 | val toString : char -> String.string 46 | val fromCString : String.string -> char option 47 | val toCString : char -> String.string 48 | end; 49 | -------------------------------------------------------------------------------- /infrastructure/PRETTY_PRINT-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * A generic pretty printer. 5 | * 6 | * Based on: 7 | * Philip Wadler. "A prettier printer" 8 | * http://cm.bell-labs.com/cm/cs/who/wadler/ 9 | * and Christian Lindig's port to OCaml. 10 | * 11 | * The semantics has been extended to allow 4 different kinds of 12 | * groups (`boxes'), 2 modes of nesting, and varying break representations. 13 | * This is no longer easily described by an algebra though, and the `below' 14 | * combinator looses optimality. 15 | *) 16 | 17 | signature PRETTY_PRINT = 18 | sig 19 | type doc 20 | 21 | val empty : doc (* empty document *) 22 | val break : doc (* space or line break *) 23 | val ebreak : doc (* empty or line break *) 24 | val text : string -> doc (* raw text *) 25 | 26 | val ^^ : doc * doc -> doc (* concatenation *) 27 | val ^/^ : doc * doc -> doc (* concatenation with break *) 28 | 29 | val hbox : doc -> doc (* horizontal box *) 30 | val vbox : doc -> doc (* vertical box *) 31 | val fbox : doc -> doc (* fill box (h and v) *) 32 | val abox : doc -> doc (* auto box (h or v) *) 33 | 34 | val nest : int -> doc -> doc (* indentation by k char's *) 35 | val below : doc -> doc (* keep current indentation *) 36 | 37 | val isEmpty : doc -> bool 38 | 39 | val toString : doc * int -> string 40 | val output : TextIO.outstream * doc * int -> unit 41 | end; 42 | -------------------------------------------------------------------------------- /elab/PPStaticBasis.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML pretty printing of the static basis 5 | *) 6 | 7 | structure PPStaticBasis : PP_STATIC_BASIS = 8 | struct 9 | (* Import *) 10 | 11 | type Basis = StaticObjectsModule.Basis 12 | type SigEnv = StaticObjectsModule.SigEnv 13 | type FunEnv = StaticObjectsModule.FunEnv 14 | 15 | open PrettyPrint 16 | open PPMisc 17 | 18 | infixr ^^ ^/^ 19 | 20 | 21 | (* Simple objects *) 22 | 23 | fun ppSigId sigid = text(SigId.toString sigid) 24 | fun ppFunId funid = text(FunId.toString funid) 25 | 26 | 27 | (* Environments *) 28 | 29 | fun ppSigEnv G = 30 | SigIdMap.foldri 31 | (fn(sigid, Sigma, doc) => 32 | fbox(nest( 33 | hbox(text "signature" ^/^ ppSigId sigid ^/^ text "=") ^/^ 34 | PPStaticEnv.ppSig Sigma 35 | )) ^/^ doc 36 | ) empty G 37 | 38 | fun ppFunEnv F = 39 | FunIdMap.foldri 40 | (fn(funid, (T, (E, Sigma)), doc) => 41 | fbox(nest( 42 | hbox(text "functor" ^/^ ppFunId funid) ^^ ebreak ^^ 43 | fbox(nest( 44 | text "(" ^^ 45 | hbox(text "Arg" ^/^ text ":") ^/^ PPStaticEnv.ppSig(T, E) ^^ 46 | text ")" 47 | )) ^/^ text ":" ^/^ PPStaticEnv.ppSig Sigma 48 | )) ^/^ doc 49 | ) empty F 50 | 51 | 52 | (* Basis *) 53 | 54 | fun ppBasis (T, F, G, E) = 55 | vbox( 56 | PPStaticEnv.ppTyNameSet T ^/^ 57 | ppSigEnv G ^/^ 58 | ppFunEnv F ^/^ 59 | PPStaticEnv.ppEnv E ^/^ 60 | text "" 61 | ) 62 | end; 63 | -------------------------------------------------------------------------------- /sh/make.bat.in: -------------------------------------------------------------------------------- 1 | rem (c) Andreas Rossberg 2001-2025 2 | rem 3 | rem Simple minded batch file to build HaMLet under Dos/Windows 4 | 5 | set files= 6 | 7 | if "%1" == "with-alice" goto alice 8 | if "%1" == "with-mlkit" goto mlkit 9 | if "%1" == "with-mlton" goto mlton 10 | if "%1" == "with-mosml" goto mosml 11 | if "%1" == "with-poly" goto poly 12 | if "%1" == "with-smlnj" goto smlnj 13 | if "%1" == "clean" goto clean 14 | if "%1" == "distclean" goto distclean 15 | 16 | :alice 17 | alicec --no-warn-conventions --no-warn-unused-imports --dependency-file Makefile-alice.depend --recursive-compilation -c main/wrap-alice.sml 18 | alicelink --include ${PWD} main/wrap-alice -o hamlet.ozf 19 | copy sh/hamlet-alice.sh${BAT} hamlet${BAT} 20 | goto end 21 | 22 | :mlkit 23 | echo ML Kit not supported via make.bat - please use Cygwin. 24 | goto end 25 | 26 | :mlton 27 | mlton -output hamlet.exe sources.cm 28 | goto end 29 | 30 | :mosml 31 | for %%file in (%files%) do mosmlc -c -toplevel %%file 32 | mosmlc -toplevel wrap-mosml.sml -o hamlet.exe 33 | goto end 34 | 35 | :poly 36 | echo Poly/ML not supported via make.bat - please use Cygwin. 37 | goto end 38 | 39 | :smlnj 40 | sml
LargeWord.word 18 | val toLargeX : word -> LargeWord.word 19 | val fromLarge : LargeWord.word -> word 20 | val toLargeInt : word -> LargeInt.int 21 | val toLargeIntX : word -> LargeInt.int 22 | val fromLargeInt : LargeInt.int -> word 23 | val toInt : word -> Int.int 24 | val toIntX : word -> Int.int 25 | val fromInt : Int.int -> word 26 | val orb : word * word -> word 27 | val xorb : word * word -> word 28 | val andb : word * word -> word 29 | val notb : word -> word 30 | val << : word * Word.word -> word 31 | val >> : word * Word.word -> word 32 | val ~>> : word * Word.word -> word 33 | val + : word * word -> word 34 | val - : word * word -> word 35 | val * : word * word -> word 36 | val div : word * word -> word 37 | val mod : word * word -> word 38 | val ~ : word -> word 39 | val compare : word * word -> order 40 | val > : word * word -> bool 41 | val < : word * word -> bool 42 | val >= : word * word -> bool 43 | val <= : word * word -> bool 44 | val min : word * word -> word 45 | val max : word * word -> word 46 | val fmt : StringCvt.radix -> word -> string 47 | val toString : word -> string 48 | val scan : StringCvt.radix -> (char, 'a) StringCvt.reader -> (word, 'a) StringCvt.reader 49 | val fromString : string -> word option 50 | end; 51 | -------------------------------------------------------------------------------- /eval/DYNAMIC_BASIS-sig.sml: -------------------------------------------------------------------------------- 1 | (* 2 | * (c) Andreas Rossberg 1999-2025 3 | * 4 | * Standard ML dynamic basis and environments of modules 5 | * 6 | * Definition, Section 7.2 7 | *) 8 | 9 | signature DYNAMIC_BASIS = 10 | sig 11 | (* Import *) 12 | 13 | type StrId = IdsCore.StrId 14 | type SigId = IdsModule.SigId 15 | type FunId = IdsModule.FunId 16 | type longStrId = IdsCore.longStrId 17 | type longTyCon = IdsCore.longTyCon 18 | 19 | type Env = DynamicObjectsCore.Env 20 | type ValEnv = DynamicObjectsCore.ValEnv 21 | type StrEnv = DynamicObjectsCore.StrEnv 22 | type SigEnv = DynamicObjectsModule.SigEnv 23 | type FunEnv = DynamicObjectsModule.FunEnv 24 | type Int = DynamicObjectsModule.Int 25 | type FunctorClosure = DynamicObjectsModule.FunctorClosure 26 | type Basis = DynamicObjectsModule.Basis 27 | 28 | 29 | (* Operations *) 30 | 31 | val empty : Basis 32 | val fromE : Env -> Basis 33 | val fromF : FunEnv -> Basis 34 | val fromG : SigEnv -> Basis 35 | 36 | val Eof : Basis -> Env 37 | 38 | val plus : Basis * Basis -> Basis 39 | val plusSE : Basis * StrEnv -> Basis 40 | val plusG : Basis * SigEnv -> Basis 41 | val plusF : Basis * FunEnv -> Basis 42 | val plusE : Basis * Env -> Basis 43 | 44 | val findStrId : Basis * StrId -> Env option 45 | val findSigId : Basis * SigId -> Int option 46 | val findFunId : Basis * FunId -> FunctorClosure option 47 | val findLongStrId : Basis * longStrId -> Env option 48 | val findLongTyCon : Basis * longTyCon -> ValEnv option 49 | end; 50 | --------------------------------------------------------------------------------