0

我需要编写一个函数,它接受一个列表并返回一个新列表。如果列表尾部有较小的元素,则通过删除元素创建一个新列表。例如: minimum [3, 2, 5, 2, 5]应该返回[2,2,5]

minimum (x : xs)
   | null xs
      = []
   | otherwise
      = let
         minelem (x : xs) n
            =
               if x < head(xs)
                  then drop n (x : xs) --how to go to the end of the list here? 
                  else --and here?
      in minimum (x : xs) 1

minimum _
   = []   

这是家庭作业的一部分。请帮助完成此功能。

4

1 回答 1

5

我留下了一些细节供你填写。

minimum' []       = []                     -- base case
minimum' (x : xs) = case minimum' xs of    -- recursive case
    []       -> ...
    (y : ys) -> ...                        -- clue: none of the ys are smaller than y
于 2012-05-22T20:23:19.277 回答