There’s a long list of features that I’d like removed from GHC, but strangely backpack isn’t one of them. I think it desperately needs someone to advocate for it and to help improve the existing tooling (and perhaps that might even be me).
Backpack adds something to Haskell that I think is of value - it allows me to write a library where the user of the library can supply a typeclass.
For example I can write a library of utilities for higher kinded data types, and leave it up to the user whether my functions require BTraversable
from barbies or FTraversable
from hkd, or some other equivalent typeclass I didn’t even know existed.
I just need (in bkp’s single file format without anything instantiating it and completely untested)
unit my-hkd-base where
module My.HKD.Base where
-- I supply my own typeclass
class MyTraversableF t where
myTraverseF :: Applicative f => (forall a . h a -> f (g a)) -> t h -> f (t g)
-- and a newtype to wrap my things so they can be lifted into your typeclass
newtype MyTraversable t f = MyTraversable (t f)
unit my-hkd-sig where
dependency my-hkd-base
signature HKDSig where
import My.HKD.Base
-- You give me your typeclass, as well as the function(s) I need from it
class F (t :: (* -> *) -> *)
traverseF :: (F t, Applicative f) => (forall a . h a -> f (g a)) -> t h -> f (t g)
-- And supply a instance to lift my typeclass into yours (probably requires UndecidableInstances)
instance (MyTraversableF f) => F (MyTraversable f)
module My.HKD.Stuff where
import Data.Functor.Identity
import HKDSig
import My.HKD.Base
-- and the functions I provide use your specified typeclass
runIO :: F t => t IO -> IO (t Identity)
runIO = traverseF (fmap Identity)