On Jan 20, 2008 12:56 AM, Thomas Hartman <tphyahoo@gmail.com> wrote:
The code below compiles as given, however if I uncomment the tSM
function I get the overlapping instance error mentioned in the subject
line.

Can someone give me advice on how to do what I want to do?

basically I want to add, for example, (USD,1) and (USD,2) and (Euro,3)
and get result

fromList [(USD,3), (Euro,3)]

the datatypes below are more verbose but the above is the basic idea

thanks!

thomas.

*****

module TransactionRows {- ( mkTransactionRows,TransactionRows ) -} where
import Data.Monoid
import Data.List
import qualified Data.Map as M

data Currency a = Currency a
 deriving ( Show, Eq, Ord )
data Money c a = Money ( M.Map c a )
 deriving Show
instance (Num a, Ord c)=> Monoid ( Sum (Money c a) ) where
 mempty = Sum ( Money M.empty )
 Sum ( Money m1 ) `mappend` Sum ( Money m2 ) = Sum (Money m1
`plusmoney` Money m2) 

This is the overlap. Data.Monoid already defines an instance for Monoid (Sum a), so it's going to overlap with your Monoid (Sum (Money c a)).

Unless you're planning to define more than one Monoid for Money, I suggest skipping Sum entirely.

--
Dave Menendez < dave@zednenem.com>
<http://www.eyrie.org/~zednenem/>