Textonyms: Difference between revisions
→{{header|Haskell}}: Simpler with flipped tuples.
(→{{header|Haskell}}: Simpler with flipped tuples.) |
|||
Line 902:
Or, in terms of ''Data.Map'' and ''traverse'':
<lang haskell>
import qualified Data.Map as M
import Data.Maybe (mapMaybe)
Line 911 ⟶ 909:
digitEncoded :: [String] -> [(String, String)]
digitEncoded = mapMaybe (
codeGrouped :: [(String, String)] -> [[(String, String)]]
codeGrouped = groupBy (on (==)
textonymSubset :: [[(String, String)]] -> [[(String, String)]]
Line 933 ⟶ 931:
showTextonym :: Int -> [(String, String)] -> String
showTextonym w ts =
concat [justifyRight w ' ' (
justifyRight :: Int -> Char -> String -> String
Line 939 ⟶ 937:
firstColWidth :: [[(String, String)]] -> Int
firstColWidth = maximum . map (length .
main :: IO ()
Line 949 ⟶ 947:
textonyms = textonymSubset codeGroups
ambiguous = take 5 $ sortBy (flip (comparing length)) textonyms
longer = take 5 $ sortBy (flip (comparing (length .
[wa, wl] = firstColWidth <$> [ambiguous, longer]
mapM_ putStrLn $
|