|
|
|
|
|
by nandemo
5422 days ago
|
|
Just for fun I decided to rewrite his first version in Haskell. This is probably not idiomatic, though. segment_string :: String -> Set String -> Maybe String
segment_string [] _ = Nothing
segment_string str dict =
if str `member` dict
then Just str
else let pairs = zip (inits str) (tails str)
pairInDict (x, y) = x `member` dict && y `member` dict in
do (x, y) <- find pairInDict pairs
Just (x ++ " " ++ y)
|
|