Skip to content

Instantly share code, notes, and snippets.

@ndtimofeev
Created February 28, 2017 23:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ndtimofeev/f2d1d0591d47b915cb1bdefa3055de42 to your computer and use it in GitHub Desktop.
Save ndtimofeev/f2d1d0591d47b915cb1bdefa3055de42 to your computer and use it in GitHub Desktop.
{-# 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