I'm getting a missing case definition when I'm calling this
check c (n:nx) state (l:ls,r:rs)
=true,if((isprefix state c)&(r=n))
=false, otherwise
I've checked this and it works on its own no matter what I send it.
This is where I'm calling it from (warning: it's a bit badly written for now):
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
Missing case definition means that you're pattern matching and you don't cover all cases. This happens twice in the definition of your
check
function: You're matching the second parameter with the patternn:nx
, but not against the pattern[]
(so you're not covering the case that the second argument may be the empty list). Similarly you're matching the fourth argument against(l:ls, r:rs)
, not accounting for the possibility that either of the pair's elements may be the empty list.So what's happening to cause the error is that when you're calling
check
fromreadword
eithersNum
is empty or one of the lists intape
is empty.