{-# LANGUAGE LambdaCase #-} module FooBar where data FooBar = Foo | Bar data Impl = MkImpl{ baz_ :: Int, quux_ :: String } fooImpl :: Impl fooImpl = MkImpl{ baz_ = 3, quux_ = "foo" } barImpl :: Impl barImpl = MkImpl{ baz_ = 5, quux_ = "bar" } selectImpl :: FooBar -> Impl selectImpl = \case Foo -> fooImpl Bar -> barImpl baz :: FooBar -> Int baz = baz_ . selectImpl quux :: FooBar -> String quux = quux_ . selectImpl