Poly/ML 抛出异常 "toAddress"
Poly/ML Exception Cast "toAddress" raised
使用Poly/ML,我想编写一个函数来使用数组的数组构造一个 n*n 单位矩阵。
我写了:
fun equiv x y = if x = y then 1 else 0;
fun idmatrix n = Array.tabulate(n, fn i => (Array.tabulate(n, equiv i)));
编译成功,给出
> val equiv = fn: ''a -> ''a -> int
> val idmatrix = fn: int -> int array array
但是当我调用 idmatrix
idmatrix 2;
对于测试,编译器的输出是
> Exception- Cast "toAddress" raised
任何人都可以解释为什么会引发异常吗?
非常感谢!
你的代码对我来说工作正常。看the code that raises the exception,可能是32/64位地址的问题?您的 Poly/ML 是否针对正确的架构编译?
Poly/ML:
$ poly
Poly/ML 5.2 Release
> fun equiv x y = if x = y then 1 else 0;
val equiv = fn : ''a -> ''a -> int
> fun idmatrix n = Array.tabulate(n, fn i => (Array.tabulate(n, equiv i)));
val idmatrix = fn : int -> int Array.array Array.array
> idmatrix 3;
val it = fromList[fromList[1, 0, 0], fromList[0, 1, 0], fromList[0, 0, 1]]
: int Array.array Array.array
莫斯科 ML:
$ mosml
Moscow ML version 2.10
Enter `quit();' to quit.
- fun equiv x y = if x = y then 1 else 0;
> val ''a equiv = fn : ''a -> ''a -> int
- fun idmatrix n = Array.tabulate(n, fn i => (Array.tabulate(n, equiv i)));
> val idmatrix = fn : int -> int array array
- idmatrix 3;
> val it = <array> : int array array
和SML/NJ:
$ sml
Standard ML of New Jersey v110.76 [built: Sun Jun 29 03:29:51 2014]
- fun equiv x y = if x = y then 1 else 0;
stdIn:1.23 Warning: calling polyEqual
val equiv = fn : ''a -> ''a -> int
- fun idmatrix n = Array.tabulate(n, fn i => (Array.tabulate(n, equiv i)));
[autoloading]
[library $SMLNJ-BASIS/basis.cm is stable]
[autoloading done]
val idmatrix = fn : int -> int array array
- idmatrix 3;
val it = [|[|1,0,0|],[|0,1,0|],[|0,0,1|]|] : int array array
使用Poly/ML,我想编写一个函数来使用数组的数组构造一个 n*n 单位矩阵。
我写了:
fun equiv x y = if x = y then 1 else 0;
fun idmatrix n = Array.tabulate(n, fn i => (Array.tabulate(n, equiv i)));
编译成功,给出
> val equiv = fn: ''a -> ''a -> int
> val idmatrix = fn: int -> int array array
但是当我调用 idmatrix
idmatrix 2;
对于测试,编译器的输出是
> Exception- Cast "toAddress" raised
任何人都可以解释为什么会引发异常吗?
非常感谢!
你的代码对我来说工作正常。看the code that raises the exception,可能是32/64位地址的问题?您的 Poly/ML 是否针对正确的架构编译?
Poly/ML:
$ poly
Poly/ML 5.2 Release
> fun equiv x y = if x = y then 1 else 0;
val equiv = fn : ''a -> ''a -> int
> fun idmatrix n = Array.tabulate(n, fn i => (Array.tabulate(n, equiv i)));
val idmatrix = fn : int -> int Array.array Array.array
> idmatrix 3;
val it = fromList[fromList[1, 0, 0], fromList[0, 1, 0], fromList[0, 0, 1]]
: int Array.array Array.array
莫斯科 ML:
$ mosml
Moscow ML version 2.10
Enter `quit();' to quit.
- fun equiv x y = if x = y then 1 else 0;
> val ''a equiv = fn : ''a -> ''a -> int
- fun idmatrix n = Array.tabulate(n, fn i => (Array.tabulate(n, equiv i)));
> val idmatrix = fn : int -> int array array
- idmatrix 3;
> val it = <array> : int array array
和SML/NJ:
$ sml
Standard ML of New Jersey v110.76 [built: Sun Jun 29 03:29:51 2014]
- fun equiv x y = if x = y then 1 else 0;
stdIn:1.23 Warning: calling polyEqual
val equiv = fn : ''a -> ''a -> int
- fun idmatrix n = Array.tabulate(n, fn i => (Array.tabulate(n, equiv i)));
[autoloading]
[library $SMLNJ-BASIS/basis.cm is stable]
[autoloading done]
val idmatrix = fn : int -> int array array
- idmatrix 3;
val it = [|[|1,0,0|],[|0,1,0|],[|0,0,1|]|] : int array array