Skip to content

Instantly share code, notes, and snippets.

@ironhouzi
Last active May 7, 2018 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ironhouzi/2392e1aabf164a4937659017870762ef to your computer and use it in GitHub Desktop.
Save ironhouzi/2392e1aabf164a4937659017870762ef to your computer and use it in GitHub Desktop.
alpha = ["K", "Kh", "G", "Ng", "C", "Ch", "J", "Ny", "T", "Th", "D", "N", "P", "Ph", "B", "M", "Ts", "Tsh", "Dz", "W", "Zh", "Z", "'", "Y", "R", "L", "Sh", "S", "H", "A", "I", "U", "E", "O"]
data Ptree a = Pnode a [Ptree a] deriving (Eq, Show)
ptAdd :: String -> Ptree Char
ptAdd (c:cs)
| cs == [] = Pnode c []
| otherwise = Pnode c [ptAdd cs]
ptInsert :: String -> [Ptree Char] -> [Ptree Char]
ptInsert [] t = t
ptInsert s [] = [ptAdd s]
ptInsert (c:cs) ((Pnode v ch) : xs)
| c == v = (Pnode v (ptInsert cs ch)) : xs
| otherwise = [(Pnode v ch)] ++ (ptInsert (c:cs) xs)
@ironhouzi
Copy link
Author

ironhouzi commented May 7, 2018

*Main> foldr ptInsert [] (map (\x -> map toLower x) alpha)
[
    Pnode 'o' [],
    Pnode 'e' [],
    Pnode 'u' [],
    Pnode 'i' [],
    Pnode 'a' [],
    Pnode 'h' [],
    Pnode 's' [Pnode 'h' []],
    Pnode 'l' [],
    Pnode 'r' [],
    Pnode 'y' [],
    Pnode '\'' [],
    Pnode 'z' [Pnode 'h' []],
    Pnode 'w' [],
    Pnode 'd' [Pnode 'z' []],
    Pnode 't' [Pnode 's' [Pnode 'h' []],
               Pnode 'h' []],
    Pnode 'm' [],
    Pnode 'b' [],
    Pnode 'p' [Pnode 'h' []],
    Pnode 'n' [Pnode 'y' [],
               Pnode 'g' []],
    Pnode 'j' [],
    Pnode 'c' [Pnode 'h' []],
    Pnode 'g' [],
    Pnode 'k' [Pnode 'h' []]
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment