Skip to content

@rampion /Chainable.hs
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
Something went wrong with that request. Please try again.