gallery/make-pages/Records.hs

22 lines
859 B
Haskell

{-# OPTIONS_GHC -Wno-orphans #-}
{-# LANGUAGE TypeApplications #-}
module Records (HasField (..)) where
import GHC.Records
import GHC.OverloadedLabels
instance HasField x r a => IsLabel x (r -> a) where
fromLabel = getField @x
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