简体   繁体   中英

(Data.Monoid) - Sum and Product deriving Bounded and Num at the same time?

in Data.Monoid :

newtype Sum a = Sum { getSum :: a }
    deriving ( Eq       -- ^ @since 2.01
             , Ord      -- ^ @since 2.01
             , Read     -- ^ @since 2.01
             , Show     -- ^ @since 2.01
             , Bounded  -- ^ @since 2.01
             , Generic  -- ^ @since 4.7.0.0
             , Generic1 -- ^ @since 4.7.0.0
             , Num      -- ^ @since 4.7.0.0
             )

I don't understand how you could derive Num and Bounded on Sum with Integer , Float etc... which are naturally not Bounded (it's the same story for the Product wrapper).

Thanks!

I'm fairly sure this makes Sum a an instance of (say) Eq whenever a is an instance of Eq .

instance (Eq a) => Eq (Sum a) where ...

And likewise for all the other classes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM