{-# LANGUAGE TypeSynonymInstances #-}moduleData.Algebra.RingwhereimportControl.ApplicativeimportData.RatioimportqualifiedData.MapasMimportData.Algebra.Groupinfixr6*#-- | A way of forming a ring from functions. See <http://en.wikipedia.org/wiki/Group_ring>.typeGroupRingrg=M.Mapgr-- | The algebraic structure of a unital ring. Assumes that the additive operation forms an abelian group,-- that the multiplication operation forms a group, and that multiplication distributes.classGroupr=>Ringrwhereone::r(*#)::r->r->rinstanceRingBoolwhereone=True(*#)=(&&)instanceRingIntwhereone=1(*#)=(*)instanceRingIntegerwhereone=1(*#)=(*)instanceRingDoublewhereone=1(*#)=(*)instanceIntegrala=>Ring(Ratioa)where{-# SPECIALIZE instance Ring Rational #-}one=1(*#)=(*)-- | The polynomial ring.instanceRingr=>Ring(Polyr)whereone=[one](p:ps)*#(q:qs)=(p*#q):(ps*#(q:qs)^+^map(p*#)qs)_*#_=[]-- | The function ring.instanceRingr=>Ring(a->r)whereone=constone(*#)=liftA2(*#)-- | The group ring.instance(Ordg,Groupg,Ringr)=>Ring(GroupRingrg)whereone=M.singletonzeroonem*#n=M.fromListWith(^+^)[(u^+^v,f*#g)|(u,f)<-M.assocsm,(v,g)<-M.assocsn]-- | Returns the polynomial @p(x) = x@.varPoly::Ringr=>PolyrvarPoly=[zero,one]