[Haskell-beginners] Default values for Data Types?

Brandon S. Allbery KF8NH allbery at ece.cmu.edu
Wed Sep 24 22:01:30 EDT 2008


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/4a3d9a7c/attachment-0001.htm


More information about the Beginners mailing list