Tiny MML

http://ja.doukaku.org/31/より。Windows限定。Haskellもやればできる子です。

module Main (main) where

import Control.Concurrent (threadDelay)
import System.Win32 (UINT, BOOL)

foreign import stdcall unsafe "Beep" cBeep :: UINT -> UINT -> IO BOOL

play :: String -> IO ()
play []         = return ()
play ('c' : xs) = cBeep 262 500 >> play xs
play ('d' : xs) = cBeep 294 500 >> play xs
play ('e' : xs) = cBeep 330 500 >> play xs
play ('f' : xs) = cBeep 349 500 >> play xs
play ('g' : xs) = cBeep 392 500 >> play xs
play ('a' : xs) = cBeep 440 500 >> play xs
play ('b' : xs) = cBeep 494 500 >> play xs
play ('r' : xs) = threadDelay (500 * 1000) >> play xs
play (_   : xs) = play xs

main :: IO ()
main = play =<< getContents

実行例:

$ ghc -ffi -o tinymml.exe tinymml.hs
$ echo cdefedcrefgagfercrcrcrcrcdefedcr | ./tinymml.exe