wordBreak :: [String] -> String -> Maybe [String]
wordBreak xss = fmap reverse . fst . foldl f (Just [], []) where
  f (onBound, insides) y = (onBound', insides') where
    as = insides ++ case onBound of
      Nothing  -> []
      Just wds -> map (id &&& (: wds)) xss
    cs = [(bs, wds) | (b : bs, wds) <- as, b==y]
    (onBounds, insides') = partition (null . fst) cs
    onBound' = case onBounds of
      []             -> Nothing
      ((_, wds) : _) -> Just wds
wordBreak :: [String] -> String -> Maybe [String]
wordBreak xss = fmap reverse . fst . foldl f (Just [], []) where
  f (onBound, insides) y = (onBound', insides') where
    as = insides ++ case onBound of
      Nothing  -> []
      Just wds -> map (id &&& (: wds)) xss
    cs = [(bs, wds) | (b : bs, wds) <- as, b==y]
    (onBounds, insides') = partition (null . fst) cs
    onBound' = case onBounds of
      []             -> Nothing
      ((_, wds) : _) -> Just wds
wordBreak xss = fmap reverse . fst . foldl f (Just [], []) where
  f (onBound, insides) y = (onBound', insides') where
    as = insides ++ case onBound of
      Nothing  -> []
      Just wds -> map (id &&& (: wds)) xss
    cs = [(bs, wds) | (b : bs, wds) <- as, b==y]
    (onBounds, insides') = partition (null . fst) cs
    onBound' = case onBounds of
      []             -> Nothing
      ((_, wds) : _) -> Just wds