[prev in list] [next in list] [prev in thread] [next in thread] 

List:       haskell-cafe
Subject:    [Haskell-cafe]  Semigroup and Monoid instances for ReaderT
From:       Olaf Klinke <olf () aatal-apotheke ! de>
Date:       2017-03-21 20:09:58
Message-ID: CAD00E19-1164-4D77-806B-6FF76318815F () aatal-apotheke ! de
[Download RAW message or body]

Maybe I missed something, but aren't the transformers a red herring here? 

instance (Semigroup a, Applicative f) => Semigroup (f a) where
  (<>) = liftA2 (<>)

My first guess was that you could add this instance to your code without the need for \
changes to the transformers package. The problem with the semigroup instance above is \
that it conflicts with semigroup instances for f. For example, there is a semigroup \
instance for [a] when a is not a semigroup. For the declaration above, ghci 7.8.3 \
gave me:

    Overlapping instance declarations:
      instance (Semigroup a, Applicative f) => Semigroup (f a)
        -- Defined at <interactive>:4:10
      instance (Semigroup a, Semigroup b) => Semigroup (a, b)
        -- Defined in ‘Data.Semigroup'

Hence I guess you must use a newtype wrapper to declare when you want the semigroup \
instance of a and when you want the instance of f. 

Olaf
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic