How do I set default values in a record

That's the kind of thing Haskell prefers to handle in a library, rather than hacking up some hard-wired language support (which would probably cause all kinds of problems, just like it does in C++).

import Data.Default

instance Default Car where
  def = Car Nothing Nothing
          -- or whatever you want as the defaults

ford :: Car
ford = def { company = Just "Ford" }

GHCi> ford
Car {company = Just "Ford", year = Nothing}

Rather than using the Default class you can also just define a defaultCar.

You may need to use cabal to install data-default, if it's not installed in your system already.

Tags:

Haskell

Record