error-messages
error-messages copied to clipboard
"Cannot apply expression [...] to a visible type argument" does not explain the problem
MWEs:
{-# LANGUAGE TypeApplications #-}
_ = let x = pure () in x @Maybe
ghci> :set -XTypeApplications
ghci> x = pure ()
ghci> x @Maybe
Both result in the error Cannot apply expression of type ‘f0 ()’ to a visible type argument ‘Maybe’, leaving me surprised and confused. What is the issue here?
See the documentation of TypeApplications:
[Type applications] can be used whenever the full polymorphic type of the function is known. If the function is an identifier (the common case), its type is considered known only when the identifier has been given a type signature. If the identifier does not have a type signature, visible type application cannot be used.
I think the error can be improved to mention that, e.g.:
<interactive>:2:1: error:
* Cannot apply identifier 'x'
to a visible type argument `Maybe'
NB: type applications can only be used on identifiers that have type signatures
* In the expression: x @Maybe
In an equation for `it': it = x @Maybe
I notice the following type signatures are different.
ghci> p = pure
ghci> :t p
p :: forall {f :: * -> *} {a}. Applicative f => a -> f a
ghci> :t pure
pure :: forall (f :: * -> *) a . Applicative f => a -> f a
It seems this has something to do with it. I guess it would be nice if the error (or, if referenced, the manual) would mention the relevant concepts.
I like @noughtmare's suggestion. Do you think that would have solved your problem @MatthijsBlom ?
type applications
Perhaps this could instead be TypeApplications to make it more obvious this is referencing the TypeApplications pragma?