[Haskell-cafe] Default (or empty) values
Pedro Baltazar Vasconcelos
pbv at dcc.fc.up.pt
Wed Jan 17 08:23:26 EST 2007
On Wed, 17 Jan 2007 15:58:04 +0300
Max Vasin <max.vasin at gmail.com> wrote:
> Hello all!
>
> Let
>
> > data Book = Book {
> > authors :: [String],
> > title :: String,
> > editor :: Maybe String,
> > edition :: Maybe String,
> > volume :: Maybe (Int, Int), -- e.g. volume 1 of 3
> > publisher :: String,
> > year :: Int,
> > pages :: Int
> > }
One suggestion: why not make the Book type more general, e.g. a list of labeled fields:
> data Label = Author | Title | Editor | ....
> type Field = String
> newtype Book = Book [(Label,Field)]
The idea is that e.g. multiple authors would be represented by multiple entries with an "Author" label and optional fields can be omitted.
Then the empty book is simply
> empty = Book []
You might also find that this makes the processing of fields more uniform and easier to extend.
Best regards,
Pedro Vasconcelos.
More information about the Haskell-Cafe
mailing list