Type inference for type abstractions in functions
Summary
GHC Proposal #448, section 5.2, subsection 4, bullet i, reads as follows:
In synthesis mode, when examining
\ @a -> expr, we simply putain scope as a fresh skolem variable (that is, not equal to any other type) and then checkexpr. (Presumably,exprusesain a type signature.) When we infer thatexprhas typety, the expression\ @a -> exprhas typeforall a. ty. Example:\ @a (x :: a) -> xinfers the typeforall a. a -> a. (For this example, we note that\ @a (x :: a) -> xis a short-hand for\ @a -> \ (x :: a) -> x.)
Furthermore, bullet iii reads:
In synthesis mode, when examining a function argument
@ato a functionf, we bringainto scope as a fresh skolem variable and check the remainder of the arguments and the right-hand side. In the type off, we include aforall a.in the spot corresponding to the type variable argument.
So, per the proposal, TypeAbstractions should support type inference. However, at the moment, they don't:
ghci> f @a = 42 :: a
<interactive>:3:3: error: [GHC-14964]
• Invisible type pattern a has no associated forall
• In an equation for ‘f’: f @a = 42 :: a
Steps to reproduce
Try to compile this code:
{-# LANGUAGE TypeAbstractions #-}
module T25660 where
-- No signature:
f @a = 42 :: a
Expected behavior
The declaration of f is accepted with the inferred type f :: forall a. Num a => a.
Environment
- GHC version used: 9.12.1