SML#の特徴
多相レコード
# fun get_x x = #x x;
val get_x = fn : ['a#{x: 'b}, 'b.
'a -> 'b]
# get_x { x = 1, y = 2 };
val it = 1 : int
# get_x { x = 1, y = 2, z = 3 };
val it = 1 : int
10
SML#の特徴
Cが呼べる
# val puts = _import "puts" :
string -> int;
val puts = fn : string -> int
# puts "hello";
hello
val it = 10 : int
11
型の型・位置の型
structure Types = struct
val tyToString : ty -> string
end
structure Loc = struct
...
val fileNameOfPos : pos -> string
val lineOfPos : pos -> int
val colOfPos : pos -> int
end
27
型情報のダンプ
fun outputExpr stream (e : tpexp) =
case e of
TPAPPM {funTy, loc, funExp, argExpList, ...} =>
(annot stream loc funTy;
outputExpr stream funExp;
List.app (outputExpr stream) argExpList)
| TPCASEM {ruleBodyTy, loc, expList, ruleList, ...} =>
(annot stream loc ruleBodyTy;
List.app (outputExpr stream) expList;
List.app (fn x => outputExpr stream (#body x)) ruleList)
| TPCAST (exp, ty, loc) =>
(annot stream loc ty;
outputExpr stream exp)
| TPCONSTANT {loc, ty, ...} =>
annot stream loc ty
| TPDATACONSTRUCT {loc, con, argExpOpt, ...} =>
(annot stream loc (#ty con);
case argExpOpt of
SOME x =>
outputExpr stream x 28
| TPERROR =>
()
| TPEXNCONSTRUCT {argExpOpt, exn,loc, ...} =>
(case exn of
EXEXN i =>
annot stream loc (#ty i)
| EXN i =>
annot stream loc (#ty i);
case argExpOpt of
SOME x =>
outputExpr stream x
| NONE =>
())
| TPEXN_CONSTRUCTOR {exnInfo, loc} =>
annot stream loc (#ty exnInfo)
| TPEXEXN_CONSTRUCTOR {exExnInfo, loc} =>
annot stream loc (#ty exExnInfo)
| TPEXVAR (info, loc) =>
annot stream loc (#ty info)
| TPFFIIMPORT {loc, ptrExp:tpexp, stubTy:Types.ty,...} =>
(annot stream loc stubTy;
outputExpr stream ptrExp)
29