-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPresentationExamples.hs
72 lines (53 loc) · 1.69 KB
/
PresentationExamples.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
{-# LANGUAGE Arrows #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
-- dunai
import Data.MonadicStreamFunction
-- rhine
import FRP.Rhine
import FRP.Rhine.ClSF.Except
import FRP.Rhine.Clock.Realtime.Millisecond
---------------------------
verboseSum :: MSF IO Int Int
verboseSum = proc n -> do
s <- accumulateWith (+) 0 -< n
_ <- arrM print -< "The sum is now " ++ show s
returnA -< s
main1 = reactimate
$ (arrM $ const $ putStrLn "Enter a number:" >> readLn)
>>> verboseSum
>>> arr (const ())
---------------------------
type SumClock = Millisecond 100
fillUp :: Monad m => ClSF (ExceptT Double m) SumClock Double ()
fillUp = proc x -> do
s <- integral -< x
_ <- throwOn' -< (s > 5, s)
returnA -< ()
helloWorld :: ClSFExcept IO SumClock () () Empty
helloWorld = do
try $ arr (const 1) >>> fillUp
once_ $ putStrLn "Hello World!"
helloWorld
main = flow $ safely helloWorld @@ waitClock
---------------------------
data FastClock = FastClock
instance Clock m FastClock where
type Time FastClock = ()
type Tag FastClock = ()
initClock = undefined
data SlowClock = SlowClock
instance Clock m SlowClock where
type Time SlowClock = ()
type Tag SlowClock = ()
initClock = undefined
fastSignal :: ClSF m FastClock () a
fastSignal = undefined
slowProcessor :: ClSF m SlowClock b c
slowProcessor = undefined
-- uncomment the following for a clock type error
-- clockTypeError = fastSignal >>> slowProcessor
---------------------------
-- rhmain = putStrLn "Uncomment one of the example mains in the file PresentationExamples.hs!"