for learning purposes I am trying to zip 2 lists together , only if the length of both matches. ( Must be the same length ) Unfortunately , it refuses to compile. I assume there is something wrong with the signature.. Thank you in anticipation. Here is my Code:
ziptogether :: (Ord a) => [a] -> [a] -> [a]
ziptogether [] [] = 0
ziptogether (x:xs) (y:ys)
| length(x:xs) == length(y:ys) = zip (x:xs) (y:xs)
| otherwise = error "not same length"
Error:
Could not deduce (a ~ (a, a))
from the context (Ord a)
bound by the type signature for
ziptogether :: Ord a => [a] -> [a] -> [a]
at new.hs:2:16-43
`a' is a rigid type variable bound by
the type signature for ziptogether :: Ord a => [a] -> [a] -> [a]
at new.hs:2:16
Expected type: [a]
Actual type: [(a, a)]
In the return type of a call of `zip'
In the expression: zip (x : xs) (y : xs)
In an equation for `ziptogether':
ziptogether (x : xs) (y : ys)
| length (x : xs) == length (y : ys) = zip (x : xs) (y : xs)
| otherwise = error "not same length"