Uncertainty and Error Checking of Liberal Coverage for Code Running under GHC 7.6
I had a smart bit of machine level hardware that worked on GHC 7.6, but no later versions. In hindsight, I'm not entirely sure why it ever worked, but no matter how much I would like to somehow bring back this functionality:
{-# LANGUAGE
PolyKinds
, FunctionalDependencies , FlexibleInstances , FlexibleContexts
, OverlappingInstances
, ScopedTypeVariables
, TypeFamilies
, UndecidableInstances
#-}
module M where
import Data.Proxy
-- | A relation between a (maybe-partially-applied) type and that type fully
-- applied.
class Applied t (tab :: *) | t -> tab where
-- | Fully apply a type @t@ with polymorphic arguments, yielding @tab@.
applied :: Proxy t -> Proxy tab
instance Applied (t a) tab=> Applied t tab where
applied _ = applied (Proxy :: Proxy (t a))
instance t ~ tab=> Applied t tab where -- always matches when `t` is kind `*`
applied _ = Proxy :: Proxy tab
It depends on the library tagged
from GHC 7.6. We can use it like:
$ ghci-7.6.3
Prelude> :l M.hs
[1 of 1] Compiling M ( M.hs, interpreted )
Ok, modules loaded: M.
*M>
*M> :t applied (Proxy :: Proxy Either)
applied (Proxy :: Proxy Either) :: Proxy (Either a a1)
*M> (return $ Right 'a') == applied (Proxy :: Proxy Either)
True
However, this is not compiled, at least in GHC 7.8.3 or newer:
$ ghci-7.8.3
GHCi, version 7.8.3: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> :l M.hs
[1 of 1] Compiling M ( M.hs, interpreted )
M.hs:19:10:
Could not deduce (Applied (t a0) tab)
arising from the ambiguity check for an instance declaration
from the context (Applied (t a) tab)
bound by an instance declaration:
Applied (t a) tab => Applied t tab
at M.hs:19:10-42
The type variable ‘a0’ is ambiguous
In the ambiguity check for:
forall (k :: BOX) (k1 :: BOX) (t :: k1 -> k) tab (a :: k1).
Applied (t a) tab =>
Applied t tab
To defer the ambiguity check to use sites, enable AllowAmbiguousTypes
In the instance declaration for ‘Applied t tab’
M.hs:19:10:
Illegal instance declaration for ‘Applied t tab’
The liberal coverage condition fails in class ‘Applied’
for functional dependency: ‘t -> tab’
Reason: lhs type ‘t’ does not determine rhs type ‘tab’
In the instance declaration for ‘Applied t tab’
Failed, modules load
I think the answer here is related, but I don't understand this sentence yet.
Perhaps I can work around this. The only place I use this class is in the form signature:
instance (Foo tab, Applied t tab)=> Bar (Proxy t) where
Which could mean that I want to do Foo
kind-polymorphic, but it's in a big complex library and I don't know if this change is possible.
+3
source to share
1 answer