mercredi 7 février 2018

non-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).

Aucun commentaire:

Enregistrer un commentaire