
Hey, I knew about the forall (I use that to represent OO style collections, very handy), but not about the exists. Thanks. But GHC 6.8.2 (with -fglasgow-exts) does not seem to accept this "exists" keyword? Does a book or document already exist (except the website) that tells more about not standarized yet very cool Haskell thingies that make writing real world applications possible? I would LOVE such a book. Cheers, Peter On Mon, 2008-01-21 at 16:10 -0500, Stefan Monnier wrote:
How does caller choose which particular instance of Num they want?
By passing the type they want. That's what the "Num a =>" thingy does.
In object-oriented language If function return type is an interface it means that it can return any implementation of this interface, but caller can't choose which particular inplementation they want.
The full type of "f" you've given is:
forall a . (Num a) => Integer -> a
where the "forall a ." is normally not written. What you describe (a function that returns something where the type can be chosen by the function itself) would have type:
Integer -> (exists a . (Num a) => a)
I.e. the "a" is not passed as a (type) argument, but instead it's returned by the function.
What the difference between haskell class and interface in object-oriented languge such Java or C#?
From a low-level point of view, the difference is that the vtable is manipulated separately from the objects. The "Num a" basically stands for the type of the vtable (which is called "dictionary" in Haskell).
To bundle an object with its vtable as is traditionally done in OO languages, you need to create an existential package, e.g. something of type (exists a . (Num a) => a).
Stefan
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe