anagram.hs 368 B

123456789101112131415
  1. -- Slide 41
  2. import Data.List
  3. sweep::(String -> [String]) -> String -> String -> [String]
  4. sweep f l stack = case stack of
  5. [] -> [""]
  6. cur:substack -> concat [map (\xs -> cur:xs) (f (delete cur l)), sweep f l substack]
  7. ana::String -> [String]
  8. ana l = sweep (ana) l l
  9. -- Teacher version
  10. anac "" = [""]
  11. anac xs = concat (map (\c -> map (c:) (anac (delete c xs))) xs)