Skip to content

Add Typeable constraint to `fromStaticPtr`

Motivation

Currently the GHC.StaticPtr.IsStatic class is defined as

class IsStatic p where
     fromStaticPtr :: StaticPtr a -> p a

Unfortunately, this does not allow one to define an IsStatic instance for Cloud Haskell's Static. Specifically, the Cloud Haskell library distributed-static defines a function

staticPtr :: Typeable a => StaticPtr a -> Static a

The extra Typeable a constraint means we can't write fromStaticPtr = staticPtr.

Proposal

It seems like we could change the definition of IsStatic to

class IsStatic p where
     fromStaticPtr :: Typeable a => StaticPtr a -> p a

The GHC users guide says that for any StaticPtr a, a is required to have a Typeable instance, so this doesn't seem to lose any generality, and it allows instance IsStatic Static. Alternatively, one could provide a way to extract evidence of Typeable a from a StaticPtr a.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information