Textonyms: Difference between revisions

Content added Content deleted
Line 904: Line 904:
<lang haskell>{-# LANGUAGE TupleSections #-}
<lang haskell>{-# LANGUAGE TupleSections #-}


import Data.List (groupBy, sortBy, sortOn)
import Data.List (groupBy, maximum, sortBy, sortOn)
import qualified Data.Map as M
import qualified Data.Map as M
import Data.Maybe (mapMaybe)
import Data.Maybe (mapMaybe)
Line 938: Line 938:
justifyRight n c = (drop . length) <*> (replicate n c ++)
justifyRight n c = (drop . length) <*> (replicate n c ++)


firstColWidth :: [[(String, String)]] -> Int
firstColWidth = maximum . map (length . fst . head)


--------------------------- TEST ---------------------------
main :: IO ()
main :: IO ()
main = do
main = do
Line 949: Line 950:
ambiguous = take 5 $ sortBy (flip (comparing length)) textonyms
ambiguous = take 5 $ sortBy (flip (comparing length)) textonyms
longer = take 5 $ sortBy (flip (comparing (length . fst . head))) textonyms
longer = take 5 $ sortBy (flip (comparing (length . fst . head))) textonyms
[wa, wl] = firstColWidth <$> [ambiguous, longer]
colWidth xs = maximum $ map (length . fst . head) xs
[wa, wl] = colWidth <$> [ambiguous, longer]
mapM_ putStrLn $
mapM_ putStrLn $
[ "There are " ++
[ "There are " ++