Haskell将列表的内容作为参数传递

时间:2012-09-20 13:25:24

标签: haskell

  

可能重复:
  Why is such a function definition not allowed in haskell?

美好的一天!

我正在尝试编写/找到一个函数g,它将任意有限大小的列表转换为函数参数,例如

    g k [a,b,c,d] = k a b c d
    g f [a,b,c] = f a b c = ((((f) $ a) $ b) $ c)

在语法上看起来像g = foldl ($) f,但编译器合理地无法应用该函数,回答:

     ghci> let (><) f = foldl ($) f
     <interactive>:1:19:
     Occurs check: cannot construct the infinite type: b = b1 -> b
     Probable cause: `$' is applied to too many arguments
     In the first argument of `foldl', namely `($)'
     In the expression: foldl ($) f

所以我没有产生一些有效的实施。你有什么想法?提前谢谢!

0 个答案:

没有答案
相关问题