Created
April 26, 2016 12:05
-
-
Save adamgundry/7292df8cef62fd6750885be3f5f892e7 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, FlexibleInstances, FunctionalDependencies, | |
KindSignatures, MagicHash, MultiParamTypeClasses #-} | |
import GHC.TypeLits | |
import GHC.Exts | |
class HasField (x :: Symbol) r a | x r -> a where | |
getField :: Proxy# x -> r -> a | |
data Record2 (n1 :: Symbol) v1 (n2 :: Symbol) v2 = | |
Record2 v1 v2 | |
instance HasField n1 (Record2 n1 v1 n2 v2) v1 where | |
getField _ (Record2 x _) = x | |
instance HasField n2 (Record2 n1 v1 n2 v2) v2 where | |
getField _ (Record2 _ y) = y | |
z1 = getField (proxy# :: Proxy# "bar") (Record2 True 42 :: Record2 "foo" Bool "bar" Int) | |
z2 = getField (proxy# :: Proxy# "foo") (Record2 True False :: Record2 "foo" Bool "bar" Bool) | |
-- z3 = getField (proxy# :: Proxy# "foo") (Record2 True False :: Record2 "foo" Bool "foo" Bool) | |
-- | |
-- Uncommenting this line gives: | |
-- Overlapping instances for HasField "foo" (Record2 "foo" Bool "foo" Bool) Bool |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment