Limit (empty) → 1.0
raw patch · 4 files changed
+90/−0 lines, 4 filesdep +basesetup-changed
Dependencies added: base
Files
- LICENSE +19/−0
- Limit.cabal +25/−0
- Setup.hs +2/−0
- src/Data/Limit.hs +44/−0
+ LICENSE view
@@ -0,0 +1,19 @@+Copyright © 2011 Nathaniel Soares++Permission is hereby granted, free of charge, to any person obtaining a copy of+this software and associated documentation files (the "Software"), to deal in+the Software without restriction, including without limitation the rights to+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of+the Software, and to permit persons to whom the Software is furnished to do so,+subject to the following conditions:++The above copyright notice and this permission notice shall be included in all+copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE+SOFTWARE.
+ Limit.cabal view
@@ -0,0 +1,25 @@+Name: Limit+Version: 1.0+License: MIT+License-file: LICENSE+Category: Data+Synopsis: Wrapper for data that can be unbounded+Description: Limit n is like Maybe n, with (Bounded n) in place of (Just n)+ and Unbounded in place of Nothing. The only difference is that+ ∀n. Unbounded >= Bounded n, which makes Limit a good data type+ to deal with numbers that can become unbounded.+Author: Nate Soares+Maintainer: nate@natesoares.com+Build-Type: Simple+Cabal-Version: >=1.6++source-repository head+ type: git+ location: git://github.com/Soares/Bound.hs.git++Library+ Hs-Source-Dirs: src+ Build-Depends: base >= 4 && < 5+ Exposed-modules: Data.Limit+ Ghc-Options: -Wall+ Ghc-Prof-Options: -auto-all
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ src/Data/Limit.hs view
@@ -0,0 +1,44 @@+module Data.Limit+ ( Limit(Bounded,Unbounded)+ , isBounded+ , isUnbounded+ , fromBounded+ , fromLimit+ ) where++import Control.Monad ( liftM2 )++data Limit a = Bounded a | Unbounded+ deriving (Eq, Read, Show)++instance Ord a => Ord (Limit a) where+ x <= y = fromLimit (y == Unbounded) (liftM2 (<=) x y)++instance Functor Limit where+ fmap _ Unbounded = Unbounded+ fmap f (Bounded a) = Bounded (f a)++instance Monad Limit where+ Unbounded >>= _ = Unbounded+ (Bounded x) >>= k = k x++ Unbounded >> _ = Unbounded+ (Bounded _) >> k = k++ return = Bounded+ fail _ = Unbounded++isBounded :: Limit a -> Bool+isBounded Unbounded = False+isBounded _ = True++isUnbounded :: Limit a -> Bool+isUnbounded = not . isBounded++fromBounded :: Limit a -> a+fromBounded Unbounded = error "Limit.fromBounded: Unbounded" -- YOUR BAD+fromBounded (Bounded x) = x++fromLimit :: a -> Limit a -> a+fromLimit d Unbounded = d+fromLimit _ (Bounded x) = x