Netwire 2.0.0 demo

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
{-# LANGUAGE Arrows, ScopedTypeVariables #-}

module Main where

import Control.Arrow
import Control.Wire
import Text.Printf


type SimpleWire = Wire () (Kleisli IO)


mySystem :: forall a. SimpleWire a String
mySystem = someNoise <+> nothingYet
    where
    nothingYet :: SimpleWire a String
    nothingYet = constant "Got nothing yet."

    someNoise :: SimpleWire a String
    someNoise =
        proc _ -> do
            -- Get frames per second.
            fps <- avgFps 1000 -< ()

            -- Gimme output one second after program start.
            t <- time -< ()
            asSoonAs -< t > 1

            -- Sample random number generator every half second.
            x <- (| sample (noise -< ()) |) 0.5

            identity -<
                printf "Time: %8.2f | Noise: %8.2f | FPS: %8.2f"
                       t (x :: Double) fps


main :: IO ()
main = runKleisli (testWire 1000 (arr $ const ())) mySystem