小编Art*_*ung的帖子

Haskell polyvariadic函数没有参数

我正在尝试在Haskell中创建一个polyvariadic函数,我用这个答案来创建一个基本函数.这是函数的代码:

class SumRes r where 
    sumOf :: Integer -> r

instance SumRes Integer where
    sumOf = id

instance (Integral a, SumRes r) => SumRes (a -> r) where
    sumOf x = sumOf . (x +) . toInteger
Run Code Online (Sandbox Code Playgroud)

但问题是:在没有任何参数的情况下调用函数时,它不起作用.

Couldn't match expected type 'Integer' with actual type 'Integer -> r0'
    Probable cause: 'sumOf' is applied to too few arguments
Run Code Online (Sandbox Code Playgroud)

例如,我希望能够编写sumOf :: Integer并返回此函数0.

我该怎么做?

haskell functional-programming polyvariadic

4
推荐指数
1
解决办法
180
查看次数