I am learning haskell and come up with code that resembles the following:
class A a b where ident :: a -> b class B a -- every type is B instance (forall a . a) => B a -- Any a that is B is sufficient to define A -- This means that B implies A (correct?) instance (forall a . B a) => A a a where ident a = a -- So anything that requires a value to be B -- implicitly says that any B is A & and there exist -- 'common' implementation that compiler can pick up -- Which means that I can use Bs as As oops :: B a => a -> a oops a = ident a _ = oops ""
But ghc doesn’t follow this reasoning and shows two errors:
Could not deduce: a2 arising from a use of ‘ident’ from the context: B a
Could not deduce: a arising from a use of ‘oops’. In the expression: oops ""
Am I paying not enough attention and there is a reason why this code is incorrect, or is it ghc?