31 Aug 2001 12:55:45 +0200
"Cagdas Ozgenc" <firstname.lastname@example.org> writes:
> class Eq a where
> (==) :: a -> a -> Bool
> Why do we conlude that both of the "a" refer to the same type?
Because they have the same name? I'm sorry, but I don't think I
> Apparently using different types that both belonging to class Eq
> results in an error. For example
> 65 == 'a'
Yeah, that won't work. I belive the vernacular term is "apples and
> It doesn't make much sense at first, however, how do you go by implementing
> multiple polymorphism?
There's an extension, try e.g. ghc -fglasgow-exts (IIRC). Then you
class Foo a b where
foo :: a -> b -> Bool
instance Foo Char Int where
foo x y = if Char.ord x == y then True else False
> Secondly, why does Haskell distinguish between a Type and a Class?
> There seems to be no benefit of such approach.
Types are created with the 'data' keyword, and what follows is the
definition of the data type. Classes describe properties types can
have (or possible relationships betwen types), and instances are
concrete declarations of types having those properties.
Think of it as the equivalent to 'class' and 'interface' in Jave,
concrete and abstract classes in C++. Or if you're familiar with
generic programming, e.g. in CLOS, that's close to what you've got
> Thirdly, is it possible to define meta-classes in Haskell?
My dictionary fails me. What did you want to do?
Probably not - a class is something that exists at compile time, the
Haskell type system doesn't really support run-time typing stuff.
If I haven't seen further, it is by standing in the footprints of giants