Skip to content

Instantly share code, notes, and snippets.

@masaeedu
Last active May 1, 2018 02:20
Show Gist options
  • Save masaeedu/d392178a7691e9955bf4b14c8eac321a to your computer and use it in GitHub Desktop.
Save masaeedu/d392178a7691e9955bf4b14c8eac321a to your computer and use it in GitHub Desktop.

If I try to compile it with FlexibleInstances I get:

<interactive>:5:10: error:
    • The constraint ‘Foldable t’ is no smaller than the instance head
      (Use UndecidableInstances to permit this)
    • In the instance declaration for ‘(Traversable t)’

<interactive>:5:10: error:
    • The constraint ‘Applicative t’
        is no smaller than the instance head
      (Use UndecidableInstances to permit this)
    • In the instance declaration for ‘(Traversable t)’

<interactive>:5:10: error:
    • Variable ‘a’ occurs more often
        in the constraint ‘Monoid (t a)’ than in the instance head
      (Use UndecidableInstances to permit this)
    • In the instance declaration for ‘(Traversable t)’

Ok, so let's add UndecidableInstances, which results in:

<interactive>:7:10: error:
    • Could not deduce (Monoid (t a0))
      from the context: (Foldable t, Applicative t, Monoid (t a))
        bound by an instance declaration:
                   forall (t :: * -> *) a.
                   (Foldable t, Applicative t, Monoid (t a)) =>
                   Traversable t
        at <interactive>:7:10-69
      The type variable ‘a0’ is ambiguous
    • In the ambiguity check for an instance declaration
      To defer the ambiguity check to use sites, enable AllowAmbiguousTypes
      In the instance declaration for ‘(Traversable t)’

Adding AllowAmbiguousTypes:

<interactive>:10:10: error:
    • Could not deduce (Functor t)
        arising from the superclasses of an instance declaration
      from the context: (Foldable t, Applicative t, Monoid (t a))
        bound by the instance declaration at <interactive>:10:10-69
      Possible fix:
        add (Functor t) to the context of the instance declaration
    • In the instance declaration for ‘Traversable t’

<interactive>:10:10: error:
    • Could not deduce (Monoid (t a0))
        arising from a use of ‘Data.Traversable.$dmtraverse’
      from the context: (Foldable t, Applicative t, Monoid (t a))
        bound by the instance declaration at <interactive>:10:10-69
      or from: Applicative f
        bound by the type signature for:
                   traverse :: forall (f :: * -> *) a3 b.
                               Applicative f =>
                               (a3 -> f b) -> t a3 -> f (t b)
        at <interactive>:10:10-69
      The type variable ‘a0’ is ambiguous
      Relevant bindings include
        traverse :: (a3 -> f b) -> t a3 -> f (t b)
          (bound at <interactive>:10:10)
    • In the expression: Data.Traversable.$dmtraverse @t
      In an equation for ‘traverse’:
          traverse = Data.Traversable.$dmtraverse @t
      In the instance declaration for ‘Traversable t’

<interactive>:10:10: error:
    • Could not deduce (Monoid (t a1))
        arising from a use of ‘Data.Traversable.$dmmapM’
      from the context: (Foldable t, Applicative t, Monoid (t a))
        bound by the instance declaration at <interactive>:10:10-69
      or from: Monad m
        bound by the type signature for:
                   mapM :: forall (m :: * -> *) a3 b.
                           Monad m =>
                           (a3 -> m b) -> t a3 -> m (t b)
        at <interactive>:10:10-69
      The type variable ‘a1’ is ambiguous
      Relevant bindings include
        mapM :: (a3 -> m b) -> t a3 -> m (t b)
          (bound at <interactive>:10:10)
    • In the expression: Data.Traversable.$dmmapM @t
      In an equation for ‘mapM’: mapM = Data.Traversable.$dmmapM @t
      In the instance declaration for ‘Traversable t’

<interactive>:10:10: error:
    • Could not deduce (Monoid (t a2))
        arising from a use of ‘Data.Traversable.$dmsequence’
      from the context: (Foldable t, Applicative t, Monoid (t a))
        bound by the instance declaration at <interactive>:10:10-69
      or from: Monad m
        bound by the type signature for:
                   sequence :: forall (m :: * -> *) a3.
                               Monad m =>
                               t (m a3) -> m (t a3)
        at <interactive>:10:10-69
      The type variable ‘a2’ is ambiguous
      Relevant bindings include
        sequence :: t (m a3) -> m (t a3) (bound at <interactive>:10:10)
    • In the expression: Data.Traversable.$dmsequence @t
      In an equation for ‘sequence’:
          sequence = Data.Traversable.$dmsequence @t
      In the instance declaration for ‘Traversable t’

<interactive>:10:113: error:
    • Could not deduce (Monoid (t a3)) arising from a use of ‘mappend’
      from the context: (Foldable t, Applicative t, Monoid (t a))
        bound by the instance declaration at <interactive>:10:10-69
      or from: Applicative f
        bound by the type signature for:
                   sequenceA :: forall (f :: * -> *) a3.
                                Applicative f =>
                                t (f a3) -> f (t a3)
        at <interactive>:10:77-85
    • In the expression: mappend b (pure a)
      In the second argument of ‘($)’, namely
        ‘\ b a -> mappend b (pure a)’
      In the first argument of ‘foldl’, namely
        ‘(liftA2 $ \ b a -> mappend b (pure a))’
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment