From 30d350daa56352fc06de70c8edce3f4546151f88 Mon Sep 17 00:00:00 2001 From: Freyr Danielsson Date: Mon, 15 Oct 2018 22:51:33 +0000 Subject: [PATCH] add haskell powerlist function --- math/powerlist/powerlist.hs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 math/powerlist/powerlist.hs diff --git a/math/powerlist/powerlist.hs b/math/powerlist/powerlist.hs new file mode 100644 index 0000000..9e2e85b --- /dev/null +++ b/math/powerlist/powerlist.hs @@ -0,0 +1,12 @@ +powerlist l + | l == [] = [[]] + | otherwise = (powerlist (tail l)) ++ + (map (\x -> (head l):x) (powerlist (tail l))) + + +{- open shell and enter: + ghci + :load powerlist.hs + powerlist [1,2,3] + + Should return: [[],[3],[2],[2,3],[1],[1,3],[1,2],[1,2,3]] -} \ No newline at end of file