Instantly share code, notes, and snippets.

# rampion/Chainable.hs Created Feb 20, 2012

 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
to join this conversation on GitHub. Already have an account? Sign in to comment