Skip to content

Instantly share code, notes, and snippets.

@PhyrexTsai
Last active April 23, 2016 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PhyrexTsai/b4f48575d3c37a696490b907bfba7e4d to your computer and use it in GitHub Desktop.
Save PhyrexTsai/b4f48575d3c37a696490b907bfba7e4d to your computer and use it in GitHub Desktop.
Higher-order function.md

Higher-order function

We use lists to represent sets. Your task is to define a function, subsets, that receives a list as a set and returns the set of all subsets of the input set. For example:

subsets :: [Int] -> [[Int]]
subsets [] =  [ [] ]
>subsets [1,2,3] = [ [], [1], [2], [3],[1,2] [1,3], [2,3], [1,2,3] ] –順序無關 
subsets :: [Int] -> [[Int]]
subsets [] = [ [] ]
subsets (x:xs) = subsets xs ++ map (x:) (subsets xs)
main = do
print(subsets [1,2,3,4])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment