Paste: w00t
Author: | w00t |
Mode: | haskell |
Date: | Wed, 6 May 2009 12:51:43 |
Plain Text |
data Interval = Interval Double Double deriving (Show)
upperBoundary :: Interval -> Double
upperBoundary (Interval a b) = max a b
lowerBoundary :: Interval -> Double
lowerBoundary (Interval a b) = min a b
instance Eq Interval where
x == y = (lowerBoundary x == lowerBoundary y) && (upperBoundary x == upperBoundary y)
instance Num Interval where
x + y = Interval (lowerBoundary x) + (lowerBoundary y) (upperBoundary x) + (upperBoundary y)
x - y = Interval (lowerBoundary x) - (upperBoundary y) (upperBoundary x) - (lowerBoundary y)
x * y = Interval (min (lowerBoundary x) * (lowerBoundary y) (lowerBoundary x) * (upperBoundary y) (upperBoundary x) * (lowerBoundary y) (upperBoundary x) * (upperBoundary y))
(max (lowerBoundary x) * (lowerBoundary y) (lowerBoundary x) * (upperBoundary y) (upperBoundary x) * (lowerBoundary y) (upperBoundary x) * (upperBoundary y))
instance Fractional Interval where
x / y = Interval (min (lowerBoundary x) * (1/(lowerBoundary y)) (lowerBoundary x) * (1/(upperBoundary y)) (upperBoundary x) * (1/(lowerBoundary y)) (upperBoundary x) * (1/(upperBoundary y)))
(max (lowerBoundary x) * (1/(lowerBoundary y)) (lowerBoundary x) * (1/(upperBoundary y)) (upperBoundary x) * (1/(lowerBoundary y)) (upperBoundary x) * (1/(upperBoundary y)))
New Annotation