If I have a record type with lenses, is it possible to construct a new record without using the underlying record accessors?
{-# LANGUAGE TemplateHaskell #-}
import Control.Lens
import Control.Lens.TH
data Foo = Foo { _s :: String
, _b :: Bool
} deriving (Show, Eq)
makeLenses ''Foo
I could make Foo
an instance of Data.Default
and then modifiy def
with lenses, but not all record types will have sensible defaults. Does Control.Lens have its own way to do it?
Foo{}
as default, leaving all fields undefined. – WisentFoo
has strict fields. – MagisterialDefault
instance is required for strict fields and therefore probably is the correct way to go in general to avoid fragile code. – Tanjatanjoredata Foo a = Foo { _x, _y :: a }
, the lensesx
andy
individually can't change the type, since you have to modify the fieldsx
andy
at once. – Magisterial