在下面的程序中,我们知道valStr.value
假设pair
泛型类型的子类型t
。然而,当我在poly
类型中检查它时,它显示为t
。有什么方法可以在专门的poly
解释器中看到吗?t
pair
这是我跑步时得到的poly
:
> poly
Poly/ML 5.5.2 Release
> use "forum.ml";
signature PAIR =
sig val coord : pair val getFirst : pair -> real type pair end
structure Pair :
sig
val coord : pair
val getFirst : pair -> real
type pair = real * real
end
signature VALUE = sig type t val value : t end
functor createVal (R : PAIR) : VALUE
val extracted = 1.0: real
val main = fn: unit -> unit
structure valStr : VALUE
val it = (): unit
> valStr.value;
val it = (1.0, 2.0): valStr.t
(* I want to see that it is of type "pair" *)
用于生成它的代码是:
(* forum.ml *)
signature PAIR =
sig
type pair
val coord : pair
val getFirst : pair -> real
end
structure Pair =
struct
type pair = real * real
val coord = ((1.0,2.0) : pair)
fun getFirst ((x,y) : pair):real = x
end
signature VALUE =
sig
type t
val value: t
end
functor createVal(R : PAIR) : VALUE =
struct
type t = R.pair
val value = R.coord
end
structure valStr = createVal(Pair)
val extracted = Pair.getFirst valStr.value
fun main() = print (Real.toString extracted)