SML:带有常量的模式?

问题描述

我正在尝试用 SML 编写模式匹配函数,但出现此错误

Error: non-constructor applied to argument in pattern: -

我正在尝试做这样的事情:

fun illegal (c:char) i j n m =
    let
        fun legal (#"A") 0 j = true
           |legal (#"B") i 0 = true
           |legal (#"C") i n = true
           |legal (#"D") m j = true
           | legal c  i j     = false
     in
        if (legal c i j = false) then 0
        else i
     end

**I SUSPECT that the problem is that my n,m are two constants that have been valued right before. Any help appreciated
(I searched online and here I added parentheses in my chars,and tried some other stuff but my error persisted)** 

解决方法

当您进行模式匹配时,像 i 这样的东西不会检查它是否与现有的 i 绑定具有相同的值,而是引入了一个新的 i 绑定。>

当你有:

legal (#"A") 0 j = true

您真正要寻找的是:

legal (#"A") 0 j2 = j = j2