我是 ML 新手,一直在尝试简单的函数,但在尝试让函数与实数一起工作时遇到了麻烦。例如,这个反向函数....
fun reverse (nil) = nil
| reverse (x::xs) = if xs = nil then [x]
else (reverse xs) @ [x];
我得到了整数和字符串的正确输出。
- reverse [1,2,3,4];
val it = [4,3,2,1] : int list
- reverse ["a" , "b" , "c" , "d" ];
val it = ["d","c","b","a"] : string list
谁能向我解释为什么此功能不适用于实数?
这是我尝试实数时的输出...
- reverse [1.0, 2.0];
stdIn:1.2-53.9 Error: operator and operand don't agree [equality type required]
operator domain: ''Z list
operand: real list
in expression:
reverse (1.0 :: 2.0 :: nil)