Skip to content

Instantly share code, notes, and snippets.

@guipn
Created October 21, 2012 05:05
Show Gist options
  • Save guipn/3925904 to your computer and use it in GitHub Desktop.
Save guipn/3925904 to your computer and use it in GitHub Desktop.
Major encoder
{- Major.hs
- ========
-
- This program can be used to convert from strings of digits to lists of
- possible mnemonic consonant sounds, as defined by the major memory system,
- presented in correct order.
-
- Input must be served as a string, so that cases like `0001` are not misinterpreted
- as being `1`.
-
-
- Example
- -------
-
- *Main> encode "12341821"
- [["t","d"],["n"],["m"],["r"],["t","d"],["v"],["n"],["t","d"]]
-
-}
type Object = [String]
type Source = Char
table :: [(Source, Object)]
table = [ ('0', ["s", "z"]), ('1', ["t", "d"]), ('2', ["n"]), ('3', ["m"]),
('4', ["r"]), ('5', ["l"]), ('6', ["j", "ch", "sh"]),
('7', ["k", "q"]), ('8', ["v"]), ('9', ["p", "b"]) ]
fetch :: Source -> Object
fetch s = snd . head $ filter ((s ==) . fst) table
encode :: [Source] -> [Object]
encode = map fetch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment