higgledy - Haskell

Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.

James King

How do I construct values of HKD MyRecord Maybe? I've tried constructing MyRecord with Nothing for the fields but I can't get GHC to match the types. :thinking:

James King

The answer: build!

It _constructs_ a constructor function for you and is polymorphic over the f in your type. So to construct a default value of our MyRecord type where all of the fields are Nothing:

defaultMyRecord :: HKD MyRecord Maybe
defaultMyRecord = build @MyRecord @Maybe Nothing Nothing Nothing
James King

Or to create a constructor:

maybeMyRecord :: Maybe String -> Maybe String -> Maybe Int -> HKD MyRecord Maybe
maybeMyRecord = build @MyRecord @Maybe

defaultMyRecord :: HKD MyRecord Maybe
defaultMyRecord = maybeMyRecord Nothing Nothing Nothing