At 11:14 97/05/22, Koen Claessen wrote:
>..[It] already applies at less complex examples, such as the
>following:
>
>  module A where
>
>    class Foo a where
>      foo :: a -> Int
>
>    class Foo a => Bar a where
>      bar :: a -> Int
>      foo = bar
>
>  module B where
>
>    import A
>
>    instance Bar Int where
>      bar = id
>
>  module C where
>
>    import A
>
>    instance Foo Int where
>      foo = negate
>
>If you compile module B before module C, the compiler hasn't seen any
>instance of Foo Int, so it invokes the default definition, which will be
>the identity. Later it will give an error if you try to compile C.
>
>If you compile C first, then the instance is there, and the default
>definition is not invoked.

  This looks as though you end up with the multiple inheritance stuff
        Foo a <---- Bar a
           ^          ^
           |          |
       Foo Int <-- Bar Int
where the arrows mean "derivation", and "Bar Int" is the derived class to
be filled in. In C++, the writer of the "Bar Int" class has to explicitly
indicate how this class is to be derived, as the wishes for semantics may
vary. In Haskell, this is information is implicit, which causes the
problem.

  Hans Aberg





Reply via email to