Skip to content

Instantly share code, notes, and snippets.

@rblaze
Created March 3, 2015 04:59
Show Gist options
  • Save rblaze/fc36aff5cd60aa48881e to your computer and use it in GitHub Desktop.
Save rblaze/fc36aff5cd60aa48881e to your computer and use it in GitHub Desktop.
{-# LANGUAGE ScopedTypeVariables, TypeFamilies, GADTs #-}
module ZZ where
import Data.Proxy
class Def a where
def :: a
data TWrapper a b where
TW :: (Foo a, Foo b, Base a ~ b) => Proxy a -> Maybe (Proxy b) -> TWrapper a b
class Def a => Foo a where
type Base a :: *
getFooWrapper :: Proxy a -> TWrapper a (Base a)
setFooBase :: a -> Base a -> a
readBase :: forall a b. TWrapper a b -> a
readBase (TW pa pb) = case pb of
Nothing -> def
Just p -> let w = getFooWrapper p
d = (readBase w) :: b
v = setFooBase def d
in v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment