Re: [Haskell-cafe] Overloading

2013-03-10 Thread MigMit
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

Re: [Haskell-cafe] Overloading

2013-03-10 Thread ok
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

Re: [Haskell-cafe] Overloading

2013-03-10 Thread Peter Caspers
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

Re: [Haskell-cafe] Overloading

2013-03-10 Thread Daniel Trstenjak
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

Re: [Haskell-cafe] Overloading

2013-03-10 Thread Peter Caspers
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

Re: [Haskell-cafe] To seq or not to seq, that is the question

2013-03-10 Thread Albert Y. C. Lai
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)

Re: [Haskell-cafe] Overloading

2013-03-10 Thread Donn Cave
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.

Re: [Haskell-cafe] Overloading

2013-03-10 Thread Richard A. O'Keefe
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