[Haskell-cafe] Overloading
Miguel Mitrofanov
miguelimo38 at yandex.ru
Tue Mar 12 07:36:06 CET 2013
12.03.2013, 02:53, "Richard A. O'Keefe" <ok at cs.otago.ac.nz>:
> On 12/03/2013, at 10:00 AM, MigMit wrote:
>
>> On Mar 12, 2013, at 12:44 AM, "Richard A. O'Keefe" <ok at cs.otago.ac.nz> wrote:
>>> Prelude> :type (+)
>>> (+) :: Num a => a -> a -> a
>>>
>>> The predefined (+) in Haskell requires its arguments and its result
>>> to be precisely the same type.
>>>
>>> I think you had better justify the claim that Date+Period -> Date and
>>> Date+Period -> Period are possible at the same time by showing us
>>> actual code.
>> Ehm...
>>
>> import Prelude hiding (Num)
>> class SumDP a where (+) :: Date -> Period -> a
>> instance SumDP Date where date + period = <your_implementation_here>
>> instance SumDP Period where date + period = <and_here>
>
> Notice the difference?
> I said that THE PREDEFINED (+) in Haskell requires its arguments
> and its result to be precisely the same type.
>
> This example is not the predefined (+); it's another variable
> entirely that happens to have the same short name and cannot
> also add integers.
So? You've said:
> I think you had better justify the claim that Date+Period -> Date and
> Date+Period -> Period are possible at the same time by showing us
> actual code.
You didn't say THIS (+) should be the "predefined" one. And, since you were replying to what Carlos said, and he didn't say it either, my code is still a valid example.
Of course, you can refine your request so that it would mention the "predefined" (+), but that would be off-topic here.
More information about the Haskell-Cafe
mailing list