packages feed

reord (empty) → 0.0.0.2

raw patch · 3 files changed

+61/−0 lines, 3 filesdep +basesetup-changed

Dependencies added: base

Files

+ Setup.lhs view
@@ -0,0 +1,5 @@+#!/usr/bin/env runhaskell++> import Distribution.Simple+> main = defaultMain+
+ reord.cabal view
@@ -0,0 +1,23 @@+name:                   reord+version:                0.0.0.2+stability:              experimental+license:                PublicDomain++cabal-version:          >= 1.2+build-type:             Simple++author:                 James Cook <mokus@deepbondi.net>+maintainer:             James Cook <mokus@deepbondi.net>++category:               Data+synopsis:               Ad-hoc Ord instances+description:            Simple little thing to assign Ord instances+                        dynamically.  It's a bit silly, but I've found+                        use for it, along with other things like it, when+                        putting together quick hacks reusing large chunks of+                        existing code.++Library+  hs-source-dirs:       src+  exposed-modules:      Data.Ord.ReOrd+  build-depends:        base
+ src/Data/Ord/ReOrd.hs view
@@ -0,0 +1,33 @@+{-+ -      ``Util/ReOrd.hs''+ -}++module Data.Ord.ReOrd where++-- |A handy constructor which just reverses the sense of an existing 'Ord'+--  instance.+newtype Ord a => ReverseOrd a = ReverseOrd a+        deriving (Eq, Show)++instance (Ord a) => Ord (ReverseOrd a) where+        compare (ReverseOrd a) (ReverseOrd b) = compare b a++-- |A type which provides an ad-hoc 'Ord' instance for the type it wraps.+-- It is the user's responsibility to make sure that it obeys all+-- relevant laws, also taking into account the fact that when 2 items+-- are compared, only one of their 'cmp' functions is invoked (the left one)+data ReOrd a = +        ReOrd { cmp   :: a -> a -> Ordering+              , item  :: a+              }++instance Eq (ReOrd a) where+        a == b  = case cmp a (item a) (item b) of+                EQ -> True+                __ -> False+        a /= b  = case cmp a (item a) (item b) of+                EQ -> False+                __ -> True++instance Ord (ReOrd a) where+        compare a b = cmp a (item a) (item b)