我在使用SML中的列表进行模式匹配时遇到了问题。我试图创建一个采用2×2实数矩阵(定义为'a list list
)并创建一个复杂的函数(real * real)
。该矩阵被格式化为列表(使用实数制成)的列表,每个列表是一行。我知道我必须模式匹配,但我不确定如何将我的理解实现为实际代码。我的代码到目前为止是:在SML/NJ中使用列表/模式匹配
fun fromMatrix ((a::M):real matrix) : complex = (hd a, tl M);
我不断收到此错误:
stdIn:1.5-13.32 Error: right-hand-side of clause doesn't agree with function result type [tycon mismatch]
expression: real * real list list
result type: complex
in declaration:
fromMatrix =
(fn <pat> :: <pat> : real matrix => (hd <exp>,tl <exp>): complex)
是的我没有意识到我使用中缀表示法错误。谢谢! – deedex11