Created
May 25, 2018 16:24
-
-
Save abailly/abd10120b269c70afc9ad3907a7ce7e6 to your computer and use it in GitHub Desktop.
Singletons-like type to value association
This file contains hidden or 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 DataKinds #-} | |
{-# LANGUAGE GADTs #-} | |
{-# LANGUAGE KindSignatures #-} | |
{-# LANGUAGE RankNTypes #-} | |
{-# LANGUAGE TypeFamilies #-} | |
import Protolude | |
data Tag = Foo | Bar | |
data RTag (t :: Tag) where | |
RFoo :: RTag 'Foo | |
RBar :: RTag 'Bar | |
data Wrapped (t :: Tag) = | |
Wrapped { innerType :: Inner t } | |
type family Inner (t :: Tag) :: * where | |
Inner 'Foo = Int | |
Inner 'Bar = Double | |
data Wrapper where | |
Wrapper :: forall sr . Wrapped sr -> RTag sr -> Wrapper | |
foo :: Wrapper -> IO () | |
foo (Wrapper (Wrapped i) RFoo) = print (i :: Int) | |
foo (Wrapper (Wrapped d) RBar) = print (d :: Double) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment