Permutations: Difference between revisions

→‎{{header|Haskell}}: Switched foldl to foldr (more efficient, and usually the default)
(→‎{{header|Haskell}}: Slight reformulation of the Mathematica-based version, in terms of the applicative <*> operator)
(→‎{{header|Haskell}}: Switched foldl to foldr (more efficient, and usually the default))
Line 2,944:
 
ins :: a -> [a] -> Int -> [a]
ins x list n = L.intercalate [x] $ [sndfst, fstsnd] <*> [L.splitAt n list]
 
permutations :: [a] -> [[a]]
permutations =
foldlfoldr (\ac x ac -> ac >>= (fmap . ins x) <*> (enumFromTo 0 . length)) [[]]
 
main :: IO ()
9,659

edits