This code type-checks:
type T :: Type -> foreach (r :: Type) -> Type -> Type
data T k r a
type T' :: Type -> Type
type T' a = T a Identity a
Type -> Type
(ie., Identity
) here? It fails to type-check if you replace Identity
with say Int
.foreach
keyword, and how does one use it in Haskell?It's not a keyword, just an implicitly quantified type variable. It's like when you write a function
foo :: Int -> foreach r -> Double
foo = undefined
main = print ( foo 123 (Just 'w')
, foo 789 [False, True, False] )
...so foreach r
can be unified with Maybe Char
or [Bool]
but not, for instance, Float
.
Now, in your example it's even more weird, because you have not applied Identity
to anything. That means the foreach
type in T a Identity a
seems to be actually the partially applied ->
operator from Identity
s Type -> Type
signature lifted up one level... funky stuff.