这两个函数调用之间的区别

时间:2018-01-04 17:22:37

标签: haskell

unfold :: (t -> Bool) -> (t -> a) -> (t -> t) -> t -> [a]
unfold p f g x 
    | p x = []
    | otherwise = f x : unfold p f g (g x)

这是我目前正在使用的功能。它基本上是一个“展开”参数x的函数,并使用两个函数和一个谓词来确定列表何时结束。插入:

unfold (>100) (+6) (+6) 2
>> [8,14,20,26,32,38,44,50,56,62,68,74,80,86,92,98,104]

这个输出很好。 但是当我尝试:

unfold (>100) (+6) (-6) 2
<interactive>:55:1: error:
• Non type-variable argument in the constraint: Num (a -> a)
  (Use FlexibleContexts to permit this)
• When checking the inferred type
    it :: forall a. (Num (a -> a), Num a, Ord a) => [a]

我收到了这个错误。我试着找到这个错误的其他例子,但那些并没有真正帮助我。你们中有谁知道解决方案吗?

0 个答案:

没有答案