-- ------------------------ -- The Tempus Prelude -- ------------------------ -- * Functions -- id : a -> a value id = \ x . x -- curry : (a * b -> c) -> a -> b -> c value curry = \ f . \ x . \ y . f (x, y) -- uncurry : (a -> b -> c) -> a * b -> c value uncurry = \ f . \ p . f (first p) (second p) -- * Tuples -- pair : a -> b -> a * b value pair = \ x . \ y . (x, y) -- normalize : (a * b) * c -> a * b * c value normalize = \ p . (first (first p), second (first p), second p) -- onFirst : (a -> b) -> (a * c) -> (b * c) value onFirst = \ f . \ p . (f (first p), second p) -- onSecond : (a -> b) -> (c * a) -> (c * b) value onSecond = \ f . \ p . (first p, f (second p)) -- * Booleans type Bool = 1 + 1 -- false : Bool value false = left () -- true : Bool value true = right () -- branch : a -> a -> Bool -> a value branch = \ x . \ y . case (\ _ . x) (\ _ . y) -- not : Bool -> Bool value not = branch true false -- and : Bool -> Bool -> Bool value and = branch (\ _ . false) id -- or : Bool -> Bool -> Bool value or = branch id (\ _ . true) -- xor : Bool -> Bool -> Bool value xor = branch id not -- * Extended behaviors type Behavior a = a * behavior a -- Behavior : a -> behavior a -> Behavior a value Behavior = pair -- head : Behavior a -> a value head = first -- tail : Behavior a -> behavior a value tail = second -- cut : Behavior a -> event b -> event (Behavior a * b) value cut = \ b . \ e . const pair <*> expand (tail b) <.> e -- * Extended events type Event a = a + event a -- now : a -> Event a value now = left -- later : event a -> Event a value later = right -- * Event streams type EventStream a = nu s . event (a * s)