我有一个列表列表,以及一个返回包含最多项目的列表的函数:
extract ::[Plateau]->Plateau
extract(x:xs)
|x==maximumBy(compare `on` length)(x:xs)=x
|otherwise = extract(xs)
extract []=[""]
现在我需要一个函数来获取相同的结果[Plateau]
并返回一个新的[Plateau]
删除了之前最大的:
prune::[Plateau]->[Plateau]
prune(x:xs)
|x < (maximumBy(compare `on` length)(x:xs)=x : prune (xs)
|x>=maximumBy(compare `on` length)(x:xs)=[]
prune [] = []
我也称修剪为sortBy
确保最大的列表位于最后:
(extract . prune) (sortBy(compare `on` length)(plateaus))
这开始可以正常工作。我的列表plateaus
好像:
plateaus = ["01000"], ["01010", "11010", "10010"] ["00101"], ["01101", "01001"]]
这里是排序的:
[["01000"], ["00101"], ["01101", "01001"], ["01010", "11010", "10010"]]
现在,我的函数 prune 返回一个列表
[["01000"], ["00101"]]
这告诉我,出于某种原因,哈斯克尔认为
["01101", "01001"] >= ["01010", "11010", "10010"]
当我可以清楚地看到 2 >= 3 不成立时。
为什么是这样?