本文介绍了功能定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想定义一个更大的功能,该功能从列表中选择比之前更大的项目.
I would like to define a greaters function, which selects from a list items that are larger than the one before it.
例如:
greaters [1,3,2,4,3,4,5] == [3,4,4,5]
greaters [5,10,6,11,7,12] == [10,11,12]
我想出的定义是这样的:
The definition I came up with is this :
greaters :: Ord a => [a] -> [a]
到目前为止我尝试过的事情:
Things I tried so far:
greaters (x:xs) = group [ d | d <- xs, x < xs ]
有什么提示吗?
推荐答案
我将从这里开始:
greaters :: Ord a => [a] -> [a]
greaters [] = []
greaters (x:xs) = greatersImpl x xs
where
greatersImpl last [] = <fill this out>
greatersImpl last (x:xs) = <fill this out>
这篇关于功能定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!