【发布时间】:2018-01-08 15:21:47
【问题描述】:
我定义了以下数据类型:
datatype Arguments
= IntPair of int * int
| RealTriple of real * real * real
| StringSingle of string;
datatype OutputArgs = IntNum of int | RealNum of real | Str of string;
我尝试创建一个函数MultiFunc: Arguments -> OutputArgs:
fun MultiFunc(RealTriple (x, y, z)) : OutputArgs = RealNum ((x+y+z)/3.0)
| MultiFunc(IntPair (x,y)) : OutputArgs = IntNum (x+y)
| MultiFunc(StringSingle(s)) : OutputArgs = Str (implode(rev(explode(s))));
但是,当我调用 MultiFunc(1.0,2.0,3.0) 时,我收到以下错误:
stdIn:588.1-588.23 Error: operator and operand don't agree [tycon mismatch]
operator domain: Arguments
operand: real * real * real
in expression:
MultiFunc (1.0,2.0,3.0)
即由于某种原因,它无法将输入参数识别为RealTriple。
【问题讨论】: