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?
No, there is currently no way to do that. You'll have to use something like Foo{}
as default or not use lens for record construction. However, there is already an issue in lens covering this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With