# Yampa

Yampa 正在参加 2021 年度 OSC 中国开源项目评选，请投票支持！
Yampa 在 2021 年度 OSC 中国开源项目评选 中已获得 {{ projectVoteCount }} 票，请投票支持！
2021 年度 OSC 中国开源项目评选 正在火热进行中，快来投票支持你喜欢的开源项目！
2021 年度 OSC 中国开源项目评选 >>> 中场回顾
Yampa 获得 2021 年度 OSC 中国开源项目评选「最佳人气项目」 !

# Yampa

Domain-specific language embedded in Haskell for programming hybrid (mixed discrete-time and continuous-time) systems. Yampa is based on the concepts of Functional Reactive Programming (FRP) and is structured using arrow combinators.

## Installation

Yampa is available on hackage: http://hackage.haskell.org/package/Yampa.

``````\$ cabal update
\$ cabal install --lib Yampa
``````

## Examples

Getting Yampa to run is trivial. FRP is about values that change over time. In Yampa, a system is defined by a signal function (SF), which determines how the varying input and the varying output relate. For example:

```{-# LANGUAGE Arrows #-}
import FRP.Yampa

signalFunction :: SF Double Double
signalFunction = proc x -> do
y <- integral -< x
t <- time     -< ()
returnA -< y / t```

This signal function says that the output signal is the integral `y` of the input signal `x`, divided by the time `t`. The above syntax uses a Haskell extension called Arrows. If you are unhappy using arrow syntax, you can also write that code using applicative style and/or arrow combinators:

```signalFunction1 :: SF Double Double
signalFunction1 = (/) <\$> integral <*> time

signalFunction2 :: SF Double Double
signalFunction2 = (integral &&& time) >>^ (/)```

All three are equivalent, and it's a matter of which one you like best. To run this example, we need to provide the inputs, the times, and consume the output:

```firstSample :: IO Double   -- sample at time zero
firstSample =
return 1.0  -- time == 0, input == 1.0

nextSamples :: Bool -> IO (Double, Maybe Double)
nextSamples _ =
return (0.1, Just 1.0) -- time delta == 0.1s, input == 1.0

output :: Bool -> Double -> IO Bool
output _ x = do
print x     -- print the output
return False -- just continue forever```

This is a trivial example, since the integral of the constant function 1.0 over time, divided by the time, is always 1.0! Nevertheless, we are now ready to run!

``````ghci> reactimate firstSample nextSamples output signalFunction
1.0
1.0
1.0
1.0
1.0
1.0
...
``````

There is a directory with examples, which includes two basic SDL examples and one with using a Nintendo Wii Remote. You can install them with:

``````\$ cabal update
\$ cabal install Yampa -fexamples
``````

There are many programs written in Yampa:

• Haskanoid: a game that uses SDL multimedia, wiimote and kinect. It's cross platform and works in desktop, mobile, and web (compiled with GHCJS).
• Frag: a 3D first person shooting game.
• Peoplemon: a role playing game.
• Yampa-2048: an implementation of the game 2048 using Yampa and Gloss.
• MandelbrotYampa: a "hello world" using SDL2, Yampa and OpenGL.
• Haskelloids: a reproduction of the Atari 1979 classic "Asteroids"

A more comprehensive list can be obtained using the reverse dependency finder (http://packdeps.haskellers.com/reverse/Yampa), but only programs uploaded to hackage are listed.

Haskanoid, SDL cross-platform arkanoid. Peoplemon, a role playing game Yampa2048, a gloss board game

## Use in production

Keera Studios uses Yampa to create Haskell games available on Google Play for Android and iTunes for iOS:

## Backends

Yampa is backend agnostic, you can ultimately connect it to any backend you want. Existing backends include:

## Testing

Yampa comes with a sophisticated testing library that allows you to use QuickCheck to test your games, and use a time-travel debugger. These features are described in the paper Testing and Debugging Functional Reactive Programming.

You can find the additional projects at:

## Documentation and tutorials

The API of Yampa is thoroughly documented on hackage. Documentation is also available in the Haskell wiki page for Yampa.

## Related projects

• yampa-sdl2: Yampa and SDL2 made easy.
• Haskell-OpenGL-Tutorial same as here: Visually attractive mandelbrot implementation.
• graphui: Attempt to implement Graphui.
• hamball: 3D, LAN FPS game of hamster balls flying around and shooting lasers written in Haskell.
• yampa-glfw: GLFW backend.
• Haskanoid: Arkanoid clone in SDL with wiimote and kinect support that works on windows, linux, Mac, Android, and Web.
• Enpuzzled: iOS/Android haskell puzzle game.
• Pang-a-lambda: 2D arcade game inspired by the classic super-pang.
• yampa-canvas: Backend to blank-canvas / HTML5 Canvas.
• yampa-gloss: Gloss backend.
• diagrams example: Demonstration of Yampa with Diagrams.
• Keera Hails: Backend for reactive framework with GTK, WX, Qt, Android, iOS and HTML support.
• YampaSynth: Software synthesizer.
• Frag: 3D first person shooter.
• cuboid: 3D puzzle game with GLUT.
• Haskelloids: Reproduction of the Atari 1979 classic "Asteroids".
• YFrob: Yampa-based library for programming robots.
• YampaShooter: Top-down team based networked tank game.
• LaneWars: Top-down MOBA game with online multiplayer.
• Functional Reactive Virtual Reality: a fork of Yampa with extensions for VR.
• Dunai: An FRP implementation inspired by Yampa that extends SFs with a monad.
• Bearriver: API-compatible Yampa replacement built on top of dunai using Monadic Stream Functions.

## Help and collaboration

You can collaborate at least in three ways:

• File an issue (https://github.com/ivanperez-keera/Yampa/issues).
• Write documentation (send a link and/or a pull request).
• Research: we are constantly trying to improve Yampa. We'd be glad to have collaborators. If you are working on this, please, let us know.

## Authors

• Henrik Nilsson
• Antony Courtney

• Ivan Perez

### 评论

{{o.pubDate | formatDate}}

## {{formatAllHtml(o.title)}}

{{parseInt(o.viewCount) | bigNumberTransform}}

{{o.pubDate | formatDate}}