exhaustive pattern error haskell

I'm trying to parse an input from user into my datatype:

type Var = String
data FProp = V Var
            | No FProp
            | Y FProp FProp
            | O FProp FProp
            | Si FProp FProp
            | Sii FProp FProp deriving Read

using this function, by pattern matching:

f:: [String] -> FProp
f("(":"S":"i":"(":xs) = (Si (let x = fst (span (/= ")") xs) in f x) (let y = snd (span (/= ")") xs) in f y))
f("(":"Y":"(":xs) = (Y (let x = fst (span (/= ")") xs) in f x) (let y = snd (span (/= ")") xs) in f y))
f("(":"S":"i":"i":"(":xs) = (Sii (let x = fst (span (/= ")") xs) in f x) (let y = snd (span (/= ")") xs) in f y))
f("(":"O":"(":xs) = (O (let x = fst (span (/= ")") xs) in f x) (let y = snd (span (/= ")") xs) in f y))
f("(":"N":"O":"(":xs) = (No (f xs))
f ("(":"V":"(":xs) = (V(head xs))

The input would look like: "(Si (V(q)) (No (V(p))))" (equivalent to the formula: q -> ¬p).

It seemed like everything went fine, when I got this error: Non-exhaustive patterns in function f ¿Can I get some help in order to solve this? I think it might have to do with the way I defined the last recursive case (the one for V).


The function you implemented is partial, not all cases are covered. You need to add a catch-all case and return an error. To be able to do that, the function should return a type that allows modelling parsing failures (like Either Error FProp ).

In my opinion you can create a much better parser with the parsec library. There are also many great tutorials you might want to investigate.

链接地址: http://www.djcxy.com/p/43286.html

上一篇: PHP中的输出缓冲需要更多资源吗?

下一篇: 详尽的模式错误haskell