Abbreviations, automatic: Difference between revisions
m
→{{header|Haskell}}
(→{{header|Haskell}}: A rough draft for base cases in Haskell) |
|||
Line 147:
<lang haskell>import Data.List (nub)
uniquePrefixLen
withAbbrevnLengths :: String -> [String]▼
withAbbrevnLengths s =▼
let ls = lines s▼
ws = words <$> ls▼
ns = minimum . fmap length <$> ws▼
ps = abbrevLen <$> zipWith (fmap . take) ns ws▼
in zipWith (\n t -> show n ++ '\t' : t) ps ls▼
:: Eq a
=> [[a]] -> Int
let lng = length xs
in until -- the prefix length is either lng, or yields a nub of length lng
(((||) <$> (lng ==)) <*> \i -> lng == length (nub (take i <$> xs)))
succ
1
▲withAbbrevnLengths :: String -> [String]
▲withAbbrevnLengths s =
▲ let ls = lines s
▲ ws = words <$> ls
▲ ns = minimum . fmap length <$> ws
▲ in zipWith (\n t -> show n ++ '\t' : t) ps ls
main :: IO ()
|