JoelSjogren

Untitled

Jul 22nd, 2017
311
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Data.List
  2.  
  3. -- [1,2,3] -> [([],[1,2,3]), ([1],[2,3]),([1,2],[3]),([1,2,3],[])]
  4. pro0 :: [a] -> [([a], [a])]
  5. pro0 xs = zip (inits xs) (tails xs)
  6.  
  7. -- [1,2,3] -> [(1, [2,3]), (2, [1,3]), (3, [1,2])]
  8. pro1 :: [a] -> [(a, [a])]
  9. pro1 xs = withprefix [] xs
  10.   where
  11.     withprefix _ [] = []
  12.     withprefix as (b:bs) = (b, as ++ bs) : withprefix (as ++ [b]) bs
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment