我想要写在Haskell一个幂函数的函数声明:哈斯克尔Powerset的字母排序,
powerset :: Ord a => [a] -> [[a]]
不过,我试图与一个字典序使:
powerset [1,2,3] = [[], [1], [1,2], [1,2,3], [1,3], [2], [2,3], [3]]
我发现做幂的其他方式,如:
powerSet = filterM (const [True, False])
,但没有提供宝我们按字典顺序排列。有没有办法编写powerset函数来提供这个功能,或者将未排序的powerset排序到这个顺序中?
你能不能组成[sortBy( http://hackage.haskell.org/package/base-4.8.2.0/docs/Data-List.html#v:sortBy)?不是最有效的方式,但应该做的伎俩。 – Mephy