[Haskell-beginners] Default values for Data Types?

Mike Sullivan mbsullivan at gmail.com
Wed Sep 24 22:11:25 EDT 2008


On Wed, Sep 24, 2008 at 9:02 PM, Daniel Fischer <daniel.is.fischer at web.de>
wrote:

you define your default customer

cust = Customer{ customerID=0, customerName="", customerAddress=Nothing }

On Wed, Sep 24, 2008 at 9:01 PM, Brandon S. Allbery KF8NH <
allbery at ece.cmu.edu> wrote:

assuming "aCustomer" and "a" from my previous message:  aCustomer is the
custom initializer and a is a value initialized from it.


Of course, you are both right... I was referring to the case that Brandon
dealt with, where one or more of the values was not given a "default".
However, I had misread his message (taking it as saying that his syntax
would give a compilation error).

My question is well and fully answered. Thanks, everybody!
Mike





On Wed, Sep 24, 2008 at 9:01 PM, Brandon S. Allbery KF8NH <
allbery at ece.cmu.edu> wrote:

> On 2008 Sep 24, at 21:38, Mike Sullivan wrote:
>
> defaultCust2 id addr = Customer id "Bill" addr -- function which simulates
> a default value for "name"
>
> So despite the lack of syntactic sugar, the simplicity and power of
> functions can make do. One down side, however, is that you lose the
> flexibility of record syntax (unless there is an analogue for functions that
> I don't know about).
>
>
>     *Main> aCustomer{customerName = "Bob", customerID = 9}
>     Customer {customerID = 9, customerName = "Bob", customerAddress =
> Nothing}
>     *Main> a{customerName = "Bob", customerID = 9}
>     Customer {customerID = 9, customerName = "Bob", customerAddress =
> Nothing}
>
> assuming "aCustomer" and "a" from my previous message:  aCustomer is the
> custom initializer and a is a value initialized from it.
>
> --
> brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery at kf8nh.com
> system administrator [openafs,heimdal,too many hats] allbery at ece.cmu.edu
> electrical and computer engineering, carnegie mellon university    KF8NH
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20080924/30afb583/attachment.htm


More information about the Beginners mailing list