AA
Size: a a a
AA
JS
AA
R
JS
AA
AA
{-# LANGUAGE AllowAmbiguousTypes
, FlexibleInstances
, MultiParamTypeClasses
, ScopedTypeVariables
, TypeApplications
, DuplicateRecordFields
, OverloadedLabels
, FlexibleContexts
#-}
module Records where
import GHC.OverloadedLabels
import GHC.Records
instance HasField x r a => IsLabel x (r -> a) where
fromLabel = getField @x
fb r = if #bar r then #foo r else 0
f1 = fb $ FooBar 42 True
-- 42
f2 = fb $ BarFoo True 24
-- 24
data FooBar = FooBar { foo :: Int, bar :: Bool }
data BarFoo = BarFoo { bar :: Bool, foo :: Int }
JS
AA
AA
AA
AA
AA
MK
AA
AA
IK
AA
R