Created
March 3, 2015 04:59
-
-
Save rblaze/fc36aff5cd60aa48881e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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