Created
February 20, 2012 20:07
-
-
Save rampion/1871093 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Chainable ( | |
(==.), (.==.), (.==), | |
(/=.), (./=.), (./=), | |
(<.), (.<.), (.<), | |
(>.), (.>.), (.>), | |
(<=.), (.<=.), (.<=), | |
(>=.), (.>=.), (.>=), | |
) where | |
-- start Eq chain | |
(==.),(/=.) :: Eq a => a -> a -> Maybe a | |
(==.) = start (==) | |
(/=.) = start (/=) | |
-- continue Eq chain | |
(.==.),(./=.) :: Eq a => Maybe a -> a -> Maybe a | |
(.==.) = continue (==) | |
(./=.) = continue (/=) | |
-- end Eq chain | |
(.==),(./=) :: Eq a => Maybe a -> a -> Bool | |
(.==) = end (==) | |
(./=) = end (/=) | |
-- start Ord chain | |
(<.),(>.),(<=.),(>=.) :: Ord a => a -> a -> Maybe a | |
(<.) = start (<) | |
(>.) = start (>) | |
(<=.) = start (<=) | |
(>=.) = start (>=) | |
-- continue Ord chain | |
(.<.),(.>.),(.<=.),(.>=.) :: Ord a => Maybe a -> a -> Maybe a | |
(.<.) = continue (<) | |
(.>.) = continue (>) | |
(.<=.) = continue (<=) | |
(.>=.) = continue (>=) | |
-- end Ord chain | |
(.<),(.>),(.<=),(.>=) :: Ord a => Maybe a -> a -> Bool | |
(.<) = end (<) | |
(.>) = end (>) | |
(.<=) = end (<=) | |
(.>=) = end (>=) | |
-- convenience function | |
start :: (a -> a -> Bool) -> a -> a -> Maybe a | |
start f a b = if f a b then Just b else Nothing | |
continue :: (a -> a -> Bool) -> Maybe a -> a -> Maybe a | |
continue f Nothing b = Nothing | |
continue f (Just a) b = start f a b | |
end :: (a -> a -> Bool) -> Maybe a -> a -> Bool | |
end f Nothing b = False | |
end f (Just a) b = f a b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment