To test signal functions in Yampa, use the embed function. Enter the following commands in the Haskell command-line to show the header definition:
FRP.Yampa.embed :: FRP.Yampa.SF a b -> (a, [(FRP.Yampa.DTime, Maybe a)]) -> [b]
So the parameters are:
- the signal function to run
- a tuple of…
- the first input value at time=0
- and a list of…
- (time, Nothing|Just nextValue)
and return a list of values produced by the signal function.
Primitive signal functions include: time, identity and constant
main = do
putStrLn $ show $ embed time (Nothing, [(1.0, Nothing), (0.2, Nothing), (0.03, Nothing)])
putStrLn $ show $ embed time (123, [(1.0, Just 234), (0.2, Just 345), (0.03, Just 456)])
-- [0.0,1.0,1.2,1.23]
-- [0.0,1.0,1.2,1.23]
putStrLn $ show $ embed identity (123, [(1.0, Just 234), (0.2, Just 345), (0.03, Just 456)])
putStrLn $ show $ embed identity (537, [(1.0, Nothing), (0.2, Nothing), (0.03, Just 123)])
-- [123,234,345,456]
-- [537,537,537,537]
putStrLn $ show $ embed (constant 537) (Nothing, [(1.0, Nothing), (0.2, Nothing), (0.03, Nothing)])
putStrLn $ show $ embed (constant 537) (123, [(1.0, Just 234), (0.2, Just 345), (0.03, Just 456)])
-- putStrLn $ show (embed constant (123, [(1.0, Just 234), (0.2, Just 345), (0.03, Just 456)])) -- ERROR
-- [537,537,537,537]
-- [537,537,537,537]

Just wondering… Why’s that a `Maybe a` and not just an `a`?