Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Data.List
- -- [1,2,3] -> [([],[1,2,3]), ([1],[2,3]),([1,2],[3]),([1,2,3],[])]
- pro0 :: [a] -> [([a], [a])]
- pro0 xs = zip (inits xs) (tails xs)
- -- [1,2,3] -> [(1, [2,3]), (2, [1,3]), (3, [1,2])]
- pro1 :: [a] -> [(a, [a])]
- pro1 xs = withprefix [] xs
- where
- withprefix _ [] = []
- withprefix as (b:bs) = (b, as ++ bs) : withprefix (as ++ [b]) bs
Advertisement