[Haskell-cafe] Re: Default (or empty) values

Max Vasin max.vasin at gmail.com
Wed Jan 17 08:57:54 EST 2007


>>>>> "Pedro" == Pedro Baltazar Vasconcelos <pbv at dcc.fc.up.pt> writes:

Pedro> On Wed, 17 Jan 2007 15:58:04 +0300
Pedro> 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)]

Pedro> The idea is that e.g. multiple authors would be represented
Pedro> by multiple entries with an "Author" label and optional
Pedro> fields can be omitted.  Then the empty book is simply

It does not enforce presence of required fields at type level. Also it
does not enforce that fields pages and year are Int. And I want to
move as much checks to compile time as possible.

-- 
WBR,
Max Vasin.



More information about the Haskell-Cafe mailing list