a in
foo :: Int -> a -> [a]
and a in
bar :: Int -> [a]
- different type variables with the same name.
To get the expected behavior, enable the ScopedTypeVariables extension (for example, by inserting {-# LANGUAGE ScopedTypeVariables #-} at the beginning of the source file) and change the signature of type foo to
foo :: forall a. Int -> a -> [a]
When ScopedTypeVariables is not enabled, it looks like your source code was written as follows:
foo :: forall a. Int -> a -> [a] foo nv = bar n where bar :: forall a. Int -> [a] bar n = take n $ repeat v
It is not true that ghci implicitly uses ScopedTypeVariables unless you specify type annotation for bar .
Instead, the type annotation you specify for bar conflicts with the ghci infers type --- you say that bar has a type that ghci knows that it cannot have.
When you delete a type annotation, you delete the conflict.
ScopedTypeVariables changes the value of the type annotations that you supply. This does not affect the ghc type.
source share