Skip to content

Instantly share code, notes, and snippets.

@dennisvennink
Last active August 29, 2015 14:07
Show Gist options
  • Save dennisvennink/24c1cfe8bb0133206792 to your computer and use it in GitHub Desktop.
Save dennisvennink/24c1cfe8bb0133206792 to your computer and use it in GitHub Desktop.
module Main where
import Prelude hiding (until)
-- import System.CPUTime
-- 2.1 Semantic Domains
type Time = Double
type Behavior a = Time -> a
type Event a = (Time, a)
-- type Events a = [Event a]
-- 2.2 Semantics of Behaviors
-- Time
time :: Behavior Time
time = id
-- Lifting
lift0 :: a -> Behavior a
lift0 value =
\time ->
value
lift1 :: (a -> b) -> Behavior a -> Behavior b
lift1 function behavior =
\time ->
function $ behavior time
lift2 :: (a -> b -> c) -> Behavior a -> Behavior b -> Behavior c
lift2 function behavior1 behavior2 =
\time ->
function (behavior1 time) (behavior2 time)
lift3 :: (a -> b -> c -> d) -> Behavior a -> Behavior b -> Behavior c -> Behavior d
lift3 function behavior1 behavior2 behavior3 =
\time ->
function (behavior1 time) (behavior2 time) (behavior3 time)
-- Time Transformation
timeTransform :: Behavior a -> Behavior Time -> Behavior a
timeTransform behavior timeBehavior = behavior . timeBehavior
-- Integration
-- integral :: ...
-- Reactivity
until :: Behavior a -> Event (Behavior a) -> Behavior a
until behavior event =
\time ->
if time < fst event then
behavior time
else
snd event $ time
-- Event Handlers
(+=>) :: Event a -> (Time -> a -> b) -> Event b
(+=>) (eventTime, eventValue) function =
(eventTime, function eventTime eventValue)
(==>) :: Event a -> (a -> b) -> Event b
(==>) (eventTime, eventValue) function =
(eventTime, function eventValue)
(*=>) :: Event a -> (Time -> b) -> Event b
(*=>) (eventTime, _) function =
(eventTime, function eventTime)
(-=>) :: Event a -> b -> Event b
(-=>) (eventTime, _) value =
(eventTime, value)
-- Constant Events
constEv :: Time -> a -> Event a
constEv time value = (time, value)
-- External Events
-- ...
-- Predicates
-- predicate :: ...
-- Choice
-- (.|.) :: Event a -> Event a -> Event a
-- (.|.) event1 event2 =
-- now :: IO Time
-- now = getCPUTime >>= return . fromIntegral
main :: IO ()
main = undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment