You're getting the error because if you use a simple Integer like "342"
then span isDigit "342"
is just ("342",[])
, which can't match (l,a:as)
. A pattern that is supposed to always match is called an irrefutable pattern. As you've found out, patterns in let bindings are irrefutable, so...
You need to to stick to patterns that will always match in a let binding. For example you could do
readNum xs = let (i, ps) = span isDigit xs
in (case ps of
('.':as) -> let (j, qs) = span isDigit as in case qs of
b:c:bs -> if ..........
_ -> error "not enough stuff after decimal number"
_ -> ....
I gave a silly error message, but clearly you should write more sensible code there.