I wish to type spec a function f' defined inside a function f so that both of their type specs refer to the same type variable. However, when I try to do this, I get a compile error from the compiler, which assumes that the m
outside and the m
inside are not the same type variable. Any tip on how to fix this?
f :: (Monad m) => (String -> Int -> String -> m ()) -> [String] -> m ()
f _ (x:_) = f' Nothing x
where
f' :: (Maybe Int) -> String -> m () -- when I comment this line, the code compiles
f' _ _ = return ()
main = undefined
Check http://www.haskell.org/haskellwiki/Scoped_type_variables
From the link:
Scoped Type Variables are an extension to Haskell's type system that allow free type variables to be re-used in the scope of a function.