[Haskell-cafe] Extending the idea of a general Num to other types?

Peter Verswyvelen bf3 at telenet.be
Tue Sep 4 04:03:21 EDT 2007


Henning Thielemann wrote:
> Why not just
>  FancySequence.fromList [1,2,3,4]
>   or
>  FancySequence.fromList $ 1:2:3:4:[]
> ?
Yes of course, but the same could be said for numbers, e.g when you need 
an Int, you have to type (Int.fromNumber 1), (Float.fromNumber 1), 
(Double.fromNumber 1), etc... I don't like that because it makes writing 
numeric type independent generic code impossibe, so luckily the Haskell 
compiler automatically inserts fromInteger or fromRational calls to lift 
a generic number into a specific representation. But it does not provide 
the same for lists, e.g. there is no fromList function which is a member 
of some List typeclass that the compiler automatically uses just like it 
does for numbers. I think this is a bit of a discrepancy.



More information about the Haskell-Cafe mailing list