2011-11-06 67 views
2

我越来越缺少病例定义,当我调用这个缺失情况下的定义在Miranda

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 

回答

2

缺少的情况下的定义是指你的模式匹配,你不覆盖所有病例。这会在您的check函数的定义中发生两次:您将第二个参数与n:nx模式匹配,但不匹配[]模式(因此您没有覆盖第二个参数可能为空列表的情况)。同样,你也可以将第四个参数与(l:ls, r:rs)相匹配,而不是说明这个对的任何一个元素可能是空列表。

所以发生了什么导致错误是,当你从readword调用check要么sNum为空或tape的列表中的一个是空的。

+0

非常感谢你,没想到现在是在踢我自己。 – user23012

相关问题