Created
February 28, 2017 23:50
-
-
Save ndtimofeev/f2d1d0591d47b915cb1bdefa3055de42 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 DataKinds #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE Rank2Types #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
import Data.Proxy | |
import GHC.TypeLits | |
data A = A | |
data B = B | |
type family ArrItem a where | |
ArrItem A = '(0xA1, 0xA2) | |
ArrItem B = '(0xB1, 0xB2) | |
printItem :: forall a val1 val2. (ArrItem a ~ '(val1, val2), KnownNat val1, KnownNat val2) => a -> IO () | |
printItem _ = do | |
let v1 = natVal (Proxy :: Proxy val1) | |
v2 = natVal (Proxy :: Proxy val2) | |
print (v1, v2) | |
main :: IO () | |
main = do | |
printItem A | |
printItem B |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment