Implicit param allowed, but doesn't work.
ImplicitParams are awkward, I think it's awkward that they are Constraint
s.
They are not allowed as superclasses (makes sense, but then not really):
Prelude> :set -XConstraintKinds -XUndecidableSuperClasses -XImplicitParams -XAllowAmbiguousTypes
Prelude> class (?foo :: Int) => Foo a where
<interactive>:22:1: error:
• Illegal implicit parameter ‘?foo::Int’
• In the context: ?foo::Int
While checking the super-classes of class ‘Foo’
In the class declaration for ‘Foo’
However, one can "work-around" that, by tricking GHC, making syntactic ?foo
not so obvious to the compiler:
Prelude> class c => Id c where
Prelude> class (c, c ~ (?foo :: Int)) => Id c where bar :: Int; bar = ?foo
That is accepted. But (not so obviously) it doesn't work:
Prelude> let ?foo = 42 :: Int in bar @(?foo :: Int)
<interactive>:9:25: error: [GHC-39999]
• Could not deduce ‘Id (?foo::Int)’ arising from a use of ‘bar’
from the context: ?foo::Int
bound by the implicit-parameter binding for ?foo
at <interactive>:9:1-42
• In the expression: bar @(?foo :: Int)
In the expression: let ?foo = 42 :: Int in bar @(?foo :: Int)
In an equation for ‘it’:
it = let ?foo = 42 :: Int in bar @(?foo :: Int)
I feel that GHC should error earlier. It's the Id
s class (or rather bar
) definition which is wrong already.