1 patch for repository http://code.haskell.org/~wren/logfloat: Tue Jun 1 17:16:08 CEST 2010 Bas van Dijk * Data.Number.PartialOrd: shorter defaults methods for PartialOrd New patches: [Data.Number.PartialOrd: shorter defaults methods for PartialOrd Bas van Dijk **20100601151608 Ignore-this: 1b46ec1d36db33516464429d9c667ba9 ] hunk ./src/Data/Number/PartialOrd.hs 51 -- | like ('>') gt :: a -> a -> Maybe Bool - gt x y = case x `cmp` y of - Just GT -> Just True - Just _ -> Just False - Nothing -> Nothing - + gt = fmapCmp isGT + -- | like ('>=') ge :: a -> a -> Maybe Bool hunk ./src/Data/Number/PartialOrd.hs 55 - ge x y = case x `cmp` y of - Just LT -> Just False - Just _ -> Just True - Nothing -> Nothing - + ge = fmapCmp isGE + -- | like ('==') eq :: a -> a -> Maybe Bool hunk ./src/Data/Number/PartialOrd.hs 59 - eq x y = case x `cmp` y of - Just EQ -> Just True - Just _ -> Just False - Nothing -> Nothing - + eq = fmapCmp isEQ + -- | like ('/=') ne :: a -> a -> Maybe Bool hunk ./src/Data/Number/PartialOrd.hs 63 - ne x y = case x `cmp` y of - Just EQ -> Just False - Just _ -> Just True - Nothing -> Nothing - + ne = fmapCmp isNE + -- | like ('<=') le :: a -> a -> Maybe Bool hunk ./src/Data/Number/PartialOrd.hs 67 - le x y = case x `cmp` y of - Just GT -> Just False - Just _ -> Just True - Nothing -> Nothing - + le = fmapCmp isLE + -- | like ('<') lt :: a -> a -> Maybe Bool hunk ./src/Data/Number/PartialOrd.hs 71 - lt x y = case x `cmp` y of - Just LT -> Just True - Just _ -> Just False - Nothing -> Nothing - + lt = fmapCmp isLT + -- | like 'max'. The default instance returns the left argument -- when they're equal. maxPO :: a -> a -> Maybe a hunk ./src/Data/Number/PartialOrd.hs 76 - maxPO x y = do o <- x `cmp` y - case o of - GT -> Just x - EQ -> Just x - LT -> Just y - + maxPO x y = fmapCmp mx x y + where + mx GT = x + mx EQ = x + mx LT = y + -- | like 'min'. The default instance returns the left argument -- when they're equal. minPO :: a -> a -> Maybe a hunk ./src/Data/Number/PartialOrd.hs 85 - minPO x y = do o <- x `cmp` y - case o of - GT -> Just y - EQ -> Just x - LT -> Just x + minPO x y = fmapCmp mn x y + where + mn GT = y + mn EQ = x + mn LT = x infix 4 `gt`, `ge`, `eq`, `ne`, `le`, `lt`, `maxPO`, `minPO` hunk ./src/Data/Number/PartialOrd.hs 93 +fmapCmp :: PartialOrd a => (Ordering -> b) -> a -> a -> Maybe b +fmapCmp f x y = fmap f $ x `cmp` y + +isGT, isLT, isEQ, isGE, isNE, isLE :: Ordering -> Bool +isGT GT = True; isGT _ = False +isLT LT = True; isLT _ = False +isEQ EQ = True; isEQ _ = False +isLE GT = False; isLE _ = True +isGE LT = False; isGE _ = True +isNE EQ = False; isNE _ = True + instance (Ord a) => PartialOrd a where cmp x y = Just $! x `compare` y gt x y = Just $! x > y Context: [*.hs: spelling corrections from Daniel Fischer wren ng thornton **20100523235748] [logfloat-HCAR.tex: updated for May 2010 wren ng thornton **20100512044455] [TAG 0.12.1 wren ng thornton **20100319110239] Patch bundle hash: fee474c54f69bfad811d156f614864dd3a4bca0f