Reputation: 523
In the following Haskell function:
allTransformations :: String -> String -> [Transformation]
allTransformations "" "" = []
allTransformations a "" = [map (\a -> Delete a) a]
allTransformations "" b = [map (\b -> Insert b) b]
allTransformations (x:xs) (y:ys)
| x == y = map (\t -> (Copy x) : t) rest
| (length xs) < (length ys) = (map (\t -> (Insert y) : t) rest) ++ (map (\t -> (Change x y) : t) rest)
| (length xs) > (length ys) = (map (\t -> (Delete x) : t) rest) ++ (map (\t -> (Change x y) : t) rest)
where rest = allTransformations xs ys
When running allTransformations "abc" "bca"
I get the error "Non-exhaustive patterns in function allTransformations". Where is the problem?
I've covered four cases: both arguments are empty strings, the second argument is empty and the first is not, the first argument is empty and the second is not, and neither argument is empty.
This is all the possible cases, right?
Upvotes: 0
Views: 151
Reputation: 123470
You have actually covered six cases, because the fourth case you mention has three different guards:
You are missing:
And that last one is exactly the case for "abc"
and "bca"
Upvotes: 3