[Haskell-cafe] Aren't type system extensions fun?
Bulat Ziganshin
bulat.ziganshin at gmail.com
Mon May 26 17:45:04 EDT 2008
Hello Andrew,
Tuesday, May 27, 2008, 1:02:06 AM, you wrote:
> Today I was reading a potentially interesting paper, and I stumbled
> across something referred to as a "rank-2 type". Specifically,
existentials and polymorphic values are complement each other.
existential contains *some* type of given class. polymorphic function
can deal with *any* value of given class. so the only thing you can do
with existential value is to apply polymorphic function to it
f :: Class x => x -> Int
is [order-1] polymorphic function which may be applied to any type of
given class. higher-order function that receives order-n polymorphic
function as its argument called polymorphic function of order n+1:
ff :: (Class x => x -> Int) -> Int
its first argument is a *function*. polymorphic function. so you need
to call it with polymorphic function which is able to deal with *any*
value of given class. it's very different to polymorphic function:
g :: Class x => x -> Int -> Int
which accepts any value of given class. in the last case you have
polymorphic function that you can use with any value, in the first case
you need to provide yourself polymorphic function as argument
look at http://haskell.org/haskellwiki/GADTs_for_dummies
it should be helpful to understand type extensions machinery
--
Best regards,
Bulat mailto:Bulat.Ziganshin at gmail.com
More information about the Haskell-Cafe
mailing list