[Haskell-cafe] Re: iterative algorithms: how to do it in Haskell?

Bulat Ziganshin bulat.ziganshin at gmail.com
Mon Aug 21 06:35:11 EDT 2006


Hello Gene,

Monday, August 21, 2006, 12:42:17 PM, you wrote:

> being able to use +,* on any of the numeric types... but can you have
> a list of type [Num] ?? I thought that it had to be the base types of
> Int, Integer, Float, Double  etc..  No?

you can, using existentials:

data Number = forall a. (Num a, Show a) => Num a

main = print [Num (1::Int), Num (1.1::Double), Num (1::Integer)]

but that is not really very important. in my own practice,
homogeneous lists are suffice in almost all cases


you can read recent discussion on this in this topic, or look at
http://haskell.org/haskellwiki/OOP_vs_type_classes, where John
Meacham and me describes how existentials can partially emulate OOP
classes


-- 
Best regards,
 Bulat                            mailto:Bulat.Ziganshin at gmail.com



More information about the Haskell-Cafe mailing list