I'm working on a complicated function in yesod. It has a lot of functions in the where portion that are untyped, but typecheck properly. I decided to try and add a few type signatures so that I could figure out what was going on one piece at a time, but adding the type signatures caused type errors.
So I pared down the function to a simple case to post here, which still gives a similar error that I don't understand.
helper :: [(String, a)] -> [(Int, a)]
helper xs = blah
where
blah :: [(Int, a)]
blah = zip [1..10] (map snd xs)
If I remove the type signature from blah, it compiles just fine, but if I add that type signature it gives me the error:
Couldn't match type `a' with `a1'
`a' is a rigid type variable bound by
the type signature for helper :: [(String, a)] -> [(Int, a)]
at Blah.hs:4:1
`a1' is a rigid type variable bound by
the type signature for blah :: [(Int, a1)] at Blah.hs:7:5
Expected type: [(String, a1)]
Actual type: [(String, a)]
In the second argument of `map', namely `xs'
In the second argument of `zip', namely `(map snd xs)'
- I also have no idea why the "a" in helper is interpretted as a different "a" than helper when typechecking goes forth.
- Why it even cares if the a's are different in the first place
- I have no idea how to figure out what type blah actually is, because I can't move it to the toplevel while still using its argument.
Edit:
Okay, I have one more edit before I mark this answered. In the code I'm using there are some constraints (Eq a, Monad monad) => etc, etc, etc. and so the solution I have doesn't quite work. So I'm modifying my sample code to be more close to the real code:
helper :: (Eq a, Num b) => b -> [(String, a)] -> (b, [(Int, a)])
helper b xs = (b+b, blah)
where
blah :: [(Int, a)]
blah = filter (\y -> fst y == 11) $ zip [1..10] (map snd xs)
If I put
helper :: forall a. (Eq a, Num b) => b -> [(String, a)] -> (b, [(Int, a)])
this doesn't work because (I assume because b is not in scope, but I can't figure out the syntax to get forall b into this type. (forall a, forall b doesn't work, forall a,b doesn't work).