1 (* Copyright (C) 1999-2007 Henry Cejtin, Matthew Fluet, Suresh
2 * Jagannathan, and Stephen Weeks.
3 * Copyright (C) 1997-2000 NEC Research Institute.
5 * MLton is released under a BSD-style license.
6 * See the file MLton-LICENSE for details.
9 functor TypeOps (S: TYPE_OPS_STRUCTS): TYPE_OPS =
17 structure RealSize = RealSize
18 structure WordSize = WordSize
20 type realSize = RealSize.t
22 type wordSize = WordSize.t
25 fun nullary tycon = con (tycon, Vector.new0 ())
27 val bool = nullary Tycon.bool
28 val cpointer = nullary Tycon.cpointer
29 val exn = nullary Tycon.exn
30 val intInf = nullary Tycon.intInf
31 val real = RealSize.memoize (fn s => nullary (Tycon.real s))
32 val thread = nullary Tycon.thread
33 val word = WordSize.memoize (fn s => nullary (Tycon.word s))
37 fun unary tycon t = con (tycon, Vector.new1 t)
39 val array = unary Tycon.array
40 val list = unary Tycon.list
41 val reff = unary Tycon.reff
42 val vector = unary Tycon.vector
43 val weak = unary Tycon.weak
46 val word8 = word WordSize.word8
47 val word8Vector = vector word8
48 val word32 = word WordSize.word32
51 fun binary tycon (t1, t2) = con (tycon, Vector.new2 (t1, t2))
53 val arrow = binary Tycon.arrow
57 Trace.trace ("TypeOps.arrow", Layout.tuple2 (layout, layout), layout) arrow
59 fun deUnaryOpt tycon t =
61 SOME (c, ts) => if Tycon.equals (c, tycon)
62 then SOME (Vector.first ts)
67 case deUnaryOpt tycon t of
69 | NONE => Error.bug "TypeOps.deUnary"
71 val deArray = deUnary Tycon.array
72 val deRef = deUnary Tycon.reff
73 val deVector = deUnary Tycon.vector
74 val deWeak = deUnary Tycon.weak
77 if 1 = Vector.length ts
79 else con (Tycon.tuple, ts)
81 val unit = tuple (Vector.new0 ())
85 SOME (c, ts) => if Tycon.equals (c, Tycon.tuple) then SOME ts else NONE
88 val isTuple = Option.isSome o deTupleOpt
93 | NONE => Error.bug "TypeOps.deTuple"
95 val unitRef = reff unit
99 SOME (c, ts) => if Tycon.equals (c, Tycon.arrow)
100 then SOME (Vector.sub (ts, 0), Vector.sub (ts, 1))
107 | NONE => Error.bug "TypeOps.deArrow"
111 ("TypeOps.deArrow", layout, Layout.tuple2 (layout, layout))