I am working on a complex function in yesod. It has many functions in that part which is untyped, but typecheck is correct. I decided to try adding a few type signatures so that I can figure out what happens one piece at a time, but adding type signatures caused type errors.
So, I reduced this function to a simple case, to post a message here that still gives a similar error, which 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 the blah, it compiles just fine, but if I add this type signature, it will give me an 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 do not know why the "a" in the helper is interpreted as a different "a" than the helper when type checking occurs.
- Why does it even bother if a differs in the first place
- I have no idea how to determine what type of drone is actually because I cannot move it to the upper level, still using its argument.
Edit:
Ok, I have one more edit before I mention this. There are some limitations in the code I use (Eq a, Monad monad) => etc, etc. Etc., And so the solution that I have does not quite work. Therefore, I modify my sample code to be closer 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 does not work because (I assume that b is not in scope, but I cannot understand the syntax to get forall b in this type. (forall a, forall b does not work, forall a, b does not work).