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]

About these ads
Categories: Uncategorized
  1. No comments yet.
  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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: