Skip to content

AllowAmbiguousTypes doesn't play well with default class methods

This example does compile,

{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE ExplicitForAll #-}

class A t where
  f :: forall x m. Monoid x => t m -> m
  f = undefined

instance A [] where
  f = undefined

and it seems that the following really ought to be equivalent to it, since all I have done is remove a method definition which is identical to the default:

{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE ExplicitForAll #-}

class A t where
  f :: forall x m. Monoid x => t m -> m
  f = undefined

instance A []

But instead GHC 8.0.2 gives an error of "Could not deduce (Monoid x0)" on the instance declaration.

(I've also first posed this as a question on stackoverflow: https://stackoverflow.com/q/46350839/402884.)

Edited by Chris Martin
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information