    {-# LANGUAGE RecursiveDo #-}
    {-----------------------------------------------------------------------------
        reactive-banana
    ------------------------------------------------------------------------------}
    module Reactive.Banana.Prim.Mid.Test where

    import Reactive.Banana.Prim.Mid

    main :: IO ()
    main :: IO ()
    main = IO ()
    test_space1

    {-----------------------------------------------------------------------------
        Functionality tests
    ------------------------------------------------------------------------------}
    test_accumL1 :: Pulse Int -> BuildIO (Pulse Int)
    test_accumL1 :: Pulse Int -> BuildIO (Pulse Int)
    test_accumL1 Pulse Int
    p1 = BuildIO (Pulse Int) -> BuildIO (Pulse Int)
    forall a. Build a -> Build a
    liftBuild (BuildIO (Pulse Int) -> BuildIO (Pulse Int))
    -> BuildIO (Pulse Int) -> BuildIO (Pulse Int)
    forall a b. (a -> b) -> a -> b
    $ do
        p2     <- (Int -> Int -> Int) -> Pulse Int -> Build (Pulse (Int -> Int))
    forall a b. (a -> b) -> Pulse a -> Build (Pulse b)
    mapP Int -> Int -> Int
    forall a. Num a => a -> a -> a
    (+) Pulse Int
    p1
        (l1,_) <- accumL 0 p2
        let l2 =  (Int -> b -> Int) -> Latch Int -> Latch (b -> Int)
    forall a b. (a -> b) -> Latch a -> Latch b
    mapL Int -> b -> Int
    forall a b. a -> b -> a
    const Latch Int
    l1
        applyP l2 p1

    test_recursion1 :: Pulse () -> BuildIO (Pulse Int)
    test_recursion1 :: Pulse () -> BuildIO (Pulse Int)
    test_recursion1 Pulse ()
    p1 = BuildIO (Pulse Int) -> BuildIO (Pulse Int)
    forall a. Build a -> Build a
    liftBuild (BuildIO (Pulse Int) -> BuildIO (Pulse Int))
    -> BuildIO (Pulse Int) -> BuildIO (Pulse Int)
    forall a b. (a -> b) -> a -> b
    $ mdo
        p2      <- applyP l2 p1
        p3      <- mapP (const (+1)) p2
        ~(l1,_) <- accumL (0::Int) p3
        let l2  =  (Int -> b -> Int) -> Latch Int -> Latch (b -> Int)
    forall a b. (a -> b) -> Latch a -> Latch b
    mapL Int -> b -> Int
    forall a b. a -> b -> a
    const Latch Int
    l1
        return p2

    -- test garbage collection

    {-----------------------------------------------------------------------------
        Space leak tests
    ------------------------------------------------------------------------------}
    test_space1 :: IO ()
    test_space1 :: IO ()
    test_space1 = (Pulse Int -> BuildIO (Pulse Int)) -> [Int] -> IO ()
    forall b a.
    Show b =>
    (Pulse a -> BuildIO (Pulse b)) -> [a] -> IO ()
    runSpaceProfile Pulse Int -> BuildIO (Pulse Int)
    test_accumL1 [Int
    1::Int .. Int
    2 Int -> Int -> Int
    forall a. Num a => a -> a -> a
    * Int
    10 Int -> Int -> Int
    forall a b. (Num a, Integral b) => a -> b -> a
    ^ (Int
    4 :: Int)]

    test_space2 :: IO ()
    test_space2 :: IO ()
    test_space2 = (Pulse () -> BuildIO (Pulse Int)) -> [()] -> IO ()
    forall b a.
    Show b =>
    (Pulse a -> BuildIO (Pulse b)) -> [a] -> IO ()
    runSpaceProfile Pulse () -> BuildIO (Pulse Int)
    test_recursion1 ([()] -> IO ()) -> [()] -> IO ()
    forall a b. (a -> b) -> a -> b
    $ () () -> [Int] -> [()]
    forall a b. a -> [b] -> [a]
    forall (f :: * -> *) a b. Functor f => a -> f b -> f a
    <$ [Int
    1::Int .. Int
    2 Int -> Int -> Int
    forall a. Num a => a -> a -> a
    * Int
    10 Int -> Int -> Int
    forall a b. (Num a, Integral b) => a -> b -> a
    ^ (Int
    4 :: Int)]