Power set: Difference between revisions

m
AppleScript Adjusting names etc to improve readability of relationship to JS and Haskell examples
m (AppleScript Adjusting names etc to improve readability of relationship to JS and Haskell examples)
Line 167:
{{Trans|JavaScript}}
(functional composition examples)
{{Trans|Haskell}}
<lang AppleScript>-- powerset :: [a] -> [[a]]
on powerset(xs)
script subSet
on lambda(aacc, x)
script prependHeadconsX
on lambda(y)
{x} & y
Line 177 ⟶ 178:
end script
aacc & map(prependHeadconsX, aacc)
end lambda
end script
Line 243 ⟶ 244:
end script
end if
end mReturn</lang>
 
-- concat :: [[a]] -> [a] | [String] -> String
on concat(xs)
script append
on lambda(a, b)
a & b
end lambda
end script
if length of xs > 0 and class of (item 1 of xs) is string then
set unit to ""
else
set unit to {}
end if
foldl(append, unit, xs)
end concat</lang>
 
{{Out}}
Line 1,436 ⟶ 1,453:
powerset (head:tail) = acc ++ map (head:) acc where acc = powerset tail</lang>
or
<lang Haskell>powersetpowerSet =:: foldr (\x acc[a] -> acc ++ map (x:) acc) [[a]]</lang>
powerset = foldr (\x acc -> acc ++ map (x:) acc) [[]]</lang>
Examples:
 
9,659

edits