[Haskell-cafe] Is it possible to represent such polymorphism?
Du Xi
sdiyazg at sjtu.edu.cn
Sun Oct 2 20:15:48 CEST 2011
Quoting Victor Gorokgov <me at rkit.pp.ru>:
> 02.10.2011 19:55, David Barbour пишет:
>> Use TypeFamilies.
>>
>>
>> {-# LANGUAGE TypeFamilies #}
>> ...
>> type family FType a :: *
>> type instance FType Char = Float
>> type instance FType Double = Int
>>
>> class ExampleClass a where
>> f :: a -> FType a
>>
>
> Better to include type in class.
>
> class ExampleClass a where
> type FType a
> f :: a -> FType a
>
> instance ExampleClass Char where
> type FType Char = Float
> f char = ...
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
I guess this is what I want, thank you all. Although I still wonder
why something so simple in C++ is actually more verbose and requires
less known features in Haskell...What was the design intent to
disallow simple overloading?
More information about the Haskell-Cafe
mailing list