[Haskell-cafe] Default (or empty) values

Colin DeVilbiss cdevilbiss at gmail.com
Wed Jan 17 09:35:56 EST 2007

On 1/17/07, Max Vasin <max.vasin at gmail.com> wrote:
> Fields of the Book datatype which are not (Maybe a)
> are required to be present.

This doesn't actually answer your question, but if those fields are
really required and you want to avoid the possibility of a "default" value
sneaking into the program through a bug, you may prefer to use
undefined instead of a non-bottom value for the required fields.  That is,

Book undefined undefined Nothing Nothing Nothing undefined undefined undefined

(lots of typing, but if a bug slips in and you get a partially-defined
book into the guts of the program, you'll die instead of silently
using invalid data.)

> > class Empty e where
> >       empty :: e
> But still I have to emplement instances by hand.

What would the strategy be here for automatically defining the instances?
For example, what are the Empty instances for

data Foo = Bar | Baz | Quux
data Foo2 = Bar2 Int | Baz2 String | Quux2 (Maybe String)

> Or may be it would be better to drop out Empty and use something else?

I see no inherent problem with Empty, just with the automated instantiation.
Then again, I'd be tempted to wait to define Empty until I saw the second
or third instance of its use.


More information about the Haskell-Cafe mailing list