当我调用它时,我得到了一个缺失的大小写定义
check c (n:nx) state (l:ls,r:rs)
=true,if((isprefix state c)&(r=n))
=false, otherwise我已经检查过了,无论我发送什么,它都会自动工作。
这就是我调用它的地方(警告:它现在写得有点糟糕):
readword input state tape
=output tape, if (((haltcheck sWord sNum state tape)=true)&(isprefix " halt" rline))
=doinst rline state tape , if ((check sWord sNum state tape)=true)
=readword tail state tape, otherwise
where
theline = dropwhile notit input
start = dropwhile isspace theline
sWord = takewhile letter start
ends = dropwhile notspace start
distart = dropwhile isspace ends
sNum = takewhile notspace distart
tail = dropwhile notspace distart
rline = takewhile notit tail发布于 2011-11-07 05:31:01
缺少大小写定义意味着你正在进行模式匹配,并且你没有覆盖所有大小写。这在check函数的定义中发生了两次:将第二个参数与模式n:nx匹配,但不与模式[]匹配(因此没有涵盖第二个参数可能是空列表的情况)。类似地,您将第四个参数与(l:ls, r:rs)进行匹配,而不考虑这对元素中的任何一个元素可能是空列表的可能性。
导致错误的原因是,当您从readword调用check时,要么sNum为空,要么tape中的某个列表为空。
https://stackoverflow.com/questions/8030483
复制相似问题