Skip to content

Instantly share code, notes, and snippets.

@Ahnfelt
Created September 13, 2012 07:55
Show Gist options
  • Save Ahnfelt/3712717 to your computer and use it in GitHub Desktop.
Save Ahnfelt/3712717 to your computer and use it in GitHub Desktop.
data Sound
= Silence
| Audio AudioData
| Volume Double Sound
| Sequence Sound Sound
data SoundM a = SoundM Sound a
instance Monad SoundM where
return a = SoundM Silence a
SoundM s a >>= f = let SoundM s' a' = f a in SoundM (Sequence s s') a'
play :: SoundM a -> IO a
play (SoundM s a) = do
p <- setup
...
close p
return a
sound :: Sound -> SoundM ()
sound s = SoundM s ()
main = do
x <- obtain audio data ...
y <- obtain audio data ...
play $ do
sound (Audio x)
sound (Volume 0.90 (Audio y))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment