On Mar 10, 2013, at 11:47 AM, Peter Caspers pcaspers1...@gmail.com wrote:
Thank you all for your answers, this helps a lot. To clarify my last point ...
Also again, taking this way I can not provide several constructors taking
inputs of different types, can I ?
Sorry, didn't get what you
In C++ it is perfectly normal to have overloaded functions like
f : Int - Int - Int
f : Int - Char - Int
Something that may not be obvious about Haskell is that
Haskell does NOT have overloaded functions/operators at all.
More precisely, for any identifier and any point in a
Haskell
In C++ it is perfectly normal to have overloaded functions like
f : Int - Int - Int
f : Int - Char - Int
Something that may not be obvious about Haskell is that
Haskell does NOT have overloaded functions/operators at all.
thanks, this was the core of my question. So by example, if I define
Hi Peter,
-- smart constructor with serialNumber
date serialNumber
| serialNumber 0 = Date serialNumber
| otherwise = error (invalid serialNumber ++ show serialNumber)
Instead of raising an error it's more secure to return a Maybe value.
date :: Int - Maybe Date
date
Hi Daniel,
Instead of raising an error it's more secure to return a Maybe value.
date :: Int - Maybe Date
date serialNumber
| serialNumber 0 = Just $ Date serialNumber
| otherwise= Nothing
yes, I understand (Maybe seems the equivalent of c++'s boost::optionalT).
-- smart
On 13-03-08 11:53 PM, Edward Z. Yang wrote:
Are these equivalent? If not, under what circumstances are they not
equivalent? When should you use each?
evaluate a return b
a `seq` return b
return (a `seq` b)
Let a = div 0 0
(or whatever pure but problematic expression you like)
Peter Caspers pcaspers1...@gmail.com,
data Month = January | ...
ok, I will try to change my code in that direction. The idea is clear.
To whatever extent these algebraic data types do map to integer
values for your purposes, you can implement that by making Month an
instance of Enum.
On 11/03/2013, at 12:10 AM, Peter Caspers wrote:
thanks, this was the core of my question. So by example, if I define a Date
type as
data Date = Date Int deriving Show
representing a date by its serial number and want two constructors
(conditions are only examples here)
-- smart