2020-07-13 02:33:27 -04:00
|
|
|
{-# OPTIONS_GHC -Wno-orphans #-}
|
|
|
|
{-# LANGUAGE
|
|
|
|
FlexibleInstances, InstanceSigs, MultiParamTypeClasses, ScopedTypeVariables,
|
|
|
|
TypeApplications
|
|
|
|
#-}
|
|
|
|
module Records (HasField (..)) where
|
|
|
|
|
|
|
|
import GHC.Records
|
|
|
|
import GHC.OverloadedLabels
|
|
|
|
|
|
|
|
instance HasField x r a => IsLabel x (r -> a) where
|
|
|
|
fromLabel = getField @x
|
2020-07-18 05:46:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
instance HasField "first" (a, b) a where getField (x, _) = x
|
|
|
|
instance HasField "second" (a, b) b where getField (_, y) = y
|
|
|
|
|
|
|
|
instance HasField "first" (a, b, c) a where getField (x, _, _) = x
|
|
|
|
instance HasField "second" (a, b, c) b where getField (_, y, _) = y
|
|
|
|
instance HasField "third" (a, b, c) c where getField (_, _, z) = z
|
|
|
|
|
|
|
|
instance HasField "first" (a, b, c, d) a where getField (x, _, _, _) = x
|
|
|
|
instance HasField "second" (a, b, c, d) b where getField (_, y, _, _) = y
|
|
|
|
instance HasField "third" (a, b, c, d) c where getField (_, _, z, _) = z
|
|
|
|
instance HasField "fourth" (a, b, c, d) d where getField (_, _, _, w) = w
|