Morse code
It has been in use for more than 175 years — longer than any other electronic encoding system.



Task

Send a string as audible Morse code to an audio device   (e.g., the PC speaker).



As the standard Morse code does not contain all possible characters,
you may either ignore unknown characters in the file,
or indicate them somehow   (e.g. with a different pitch).




 
open System
open System.Threading
 
let morse = Map.ofList
                [('a', "._ "); ('b', "_... "); ('c', "_._. "); ('d', "_.. ");
                ('e', ". "); ('f', ".._. "); ('g', "__. "); ('h', ".... ");
                ('i', ".. "); ('j', ".___ "); ('k', "_._ "); ('l', "._.. ");
                ('m', "__ "); ('n', "_. "); ('o', "___ "); ('p', ".__. ");
                ('q', "__._ "); ('r', "._. "); ('s', "... "); ('t', "_ ");
                ('u', ".._ "); ('v', "..._ "); ('w', ".__ "); ('x', "_.._ ");
                ('y', "_.__ "); ('z', "__.. "); ('0', "_____ "); ('1', ".____ ");
                ('2', "..___ "); ('3', "...__ "); ('4', "...._ "); ('5', "..... ");
                ('6', "_.... "); ('7', "__... "); ('8', "___.. "); ('9', "____. ")]
 
let beep c =
    match c with
    | '.' ->
        printf "."
        Console.Beep(1200, 250)
    | '_' ->
        printf "_"
        Console.Beep(1200, 1000)
    | _ ->
        printf " "
        Thread.Sleep(125)
 
let trim (s: string) = s.Trim()
let toMorse c = Map.find c morse
let lower (s: string) = s.ToLower()
let sanitize = String.filter Char.IsLetterOrDigit
 
let send = sanitize >> lower >> String.collect toMorse >> trim >> String.iter beep
 
send "Rosetta Code"
 