Difference between revisions of "User:Echo Nolan/Reactive Banana: Straight to the Point"
Echo Nolan (talk | contribs) (New page: == Introduction == So I'm writing this tutorial as a means of teaching myself FRP and reactive-banana. It'll probably of errors and bad advice, use it at your own risk. All the tutorials...) |
Echo Nolan (talk | contribs) |
||
Line 1: | Line 1: | ||
== Introduction == |
== Introduction == |
||
− | So I'm writing this tutorial as a means of teaching myself FRP and reactive-banana. It'll probably of errors and bad advice, use it at your own risk. |
+ | So I'm writing this tutorial as a means of teaching myself FRP and reactive-banana. It'll probably be full of errors and bad advice, use it at your own risk. |
All the tutorials on FRP ''I've'' read start with a long boring theory section. This is an instant gratification article. For starters, imagine a man attempting to sharpen a banana into a deadly weapon. See? You're gratified already! Now for a boring bit: |
All the tutorials on FRP ''I've'' read start with a long boring theory section. This is an instant gratification article. For starters, imagine a man attempting to sharpen a banana into a deadly weapon. See? You're gratified already! Now for a boring bit: |
||
− | Go install mplayer: <code-bash>apt-get install mplayer # Or equivalent |
+ | Go install mplayer: <code-bash>apt-get install mplayer # Or equivalent</code-bash> |
Get the git repository associated with this tutorial: <code-bash>git clone https://github.com/enolan/rbsttp.git </code-bash> |
Get the git repository associated with this tutorial: <code-bash>git clone https://github.com/enolan/rbsttp.git </code-bash> |
||
+ | |||
+ | Install reactive-banana <code-bash> cabal install reactive-banana</code-bash> |
||
+ | |||
+ | == Musical interlude == |
||
+ | |||
+ | Cd into the git repo and open rbsttp.hs in GHCi: |
||
+ | |||
+ | <pre-bash> |
||
+ | cd rbsttp |
||
+ | ghci rbsttp.hs |
||
+ | </pre-bash> |
||
+ | |||
+ | Now, we can make some beepy noises. Try these: |
||
+ | |||
+ | <pre-haskell> |
||
+ | playNote C2 |
||
+ | playNote C6 |
||
+ | sequence_ . intersperse (threadDelay 1000000) $ map playNote [C2 ..] |
||
+ | </pre-haskell> |
||
+ | |||
+ | Play with the value passed to threadDelay a bit for some more interesting noises. It's expresssed in microseconds. |
||
+ | |||
+ | <pre-haskell> |
||
+ | sequence_ . intersperse (threadDelay 500000) $ map playNote [C2 ..] |
||
+ | sequence_ . intersperse (threadDelay 250000) $ map playNote [C2 ..] |
||
+ | sequence_ . intersperse (threadDelay 125000) $ map playNote [C2 ..] |
||
+ | sequence_ . intersperse (threadDelay 62500) $ map playNote [C2 ..] |
||
+ | </pre-haskell> |
Revision as of 17:37, 18 September 2012
Introduction
So I'm writing this tutorial as a means of teaching myself FRP and reactive-banana. It'll probably be full of errors and bad advice, use it at your own risk.
All the tutorials on FRP I've read start with a long boring theory section. This is an instant gratification article. For starters, imagine a man attempting to sharpen a banana into a deadly weapon. See? You're gratified already! Now for a boring bit:
Go install mplayer: <code-bash>apt-get install mplayer # Or equivalent</code-bash>
Get the git repository associated with this tutorial: <code-bash>git clone https://github.com/enolan/rbsttp.git </code-bash>
Install reactive-banana <code-bash> cabal install reactive-banana</code-bash>
Musical interlude
Cd into the git repo and open rbsttp.hs in GHCi:
<pre-bash> cd rbsttp ghci rbsttp.hs </pre-bash>
Now, we can make some beepy noises. Try these:
<pre-haskell> playNote C2 playNote C6 sequence_ . intersperse (threadDelay 1000000) $ map playNote [C2 ..] </pre-haskell>
Play with the value passed to threadDelay a bit for some more interesting noises. It's expresssed in microseconds.
<pre-haskell> sequence_ . intersperse (threadDelay 500000) $ map playNote [C2 ..] sequence_ . intersperse (threadDelay 250000) $ map playNote [C2 ..] sequence_ . intersperse (threadDelay 125000) $ map playNote [C2 ..] sequence_ . intersperse (threadDelay 62500) $ map playNote [C2 ..] </pre-haskell>