Home > Uncategorized > Haskell Yampa

Haskell Yampa

In my last post I mentioned that I had been looking at some Haskell libraries. Yampa has been my main interest. Using Yampa it is possible to define signals and signal processing functions. Signals are time varying functions and, for example, game ai behavior can be expressed using signals. I started out much simpler and here is my initial test:

import FRP.Yampa

add10 :: SF Int Int
add10 = arr $ (\x -> x+10)

gt20 :: SF Int Bool
gt20 = arr $ (\x -> x > 20)

composite :: SF Int Bool
composite = add10 >>> gt20

— arrow notation, http://www.haskell.org/ghc/docs/7.2.2/html/users_guide/arrow-notation.html
— requires -XArrows flag, GHC
add10ext :: SF Int Int
add10ext = proc x -> returnA -< x + 10

compositeExt :: SF Int Bool
compositeExt = proc x -> do
                 y <- identity -< x + 10
                 returnA -< y > 20

As suggested here primitive signal functions can be tested using the embed function. For example:

putStrLn $ show $ embed compositeExt (5, [(1, Nothing), (2, Just 17), (3, Nothing)])
— [False,False,True,True]

Categories: Uncategorized
  1. May 2, 2014 at 1:48 am

    Its such as you read my mind! You appear to know so much approximately this, like you wrote the book
    in it or something. I feel that you could do with some % to power the message home
    a bit, but instead of that, this is great blog. An excellent read.
    I’ll certainly be back.

  2. May 4, 2014 at 5:02 pm

    Your words are pure inspiration for me. Thanks!

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: