【问题标题】:Dot-operator in haskellhaskell中的点运算符
【发布时间】:2014-09-08 04:54:28
【问题描述】:

我有一个使用点运算符的函数。现在我想写没有点。我该怎么做?

all p = and . map p

是这样吗?

all p = and (map p)

我收到以下错误:

4.hs:8:13:
    Couldn't match expected type `[Bool]'
                with actual type `[a0] -> [b0]'
    In the return type of a call of `map'
    Probable cause: `map' is applied to too few arguments
    In the first argument of `and', namely `(map p)'
    In the expression: and (map p)

【问题讨论】:

    标签: haskell operators dot-operator


    【解决方案1】:

    删除(.) 需要明确添加点是通过您的函数“穿线”的参数。你想要类似的东西

    all p xs = and (map p xs)
    

    【讨论】:

      【解决方案2】:

      (.)definition

      f . g  =  \ x -> f (g x)
      

      扩展这个给出

      and . (map p)  =  \x -> and ((map p) x)
      

      all p x  =  and (map p x)
      

      【讨论】:

        猜你喜欢
        • 2011-02-19
        • 1970-01-01
        • 2016-12-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-07-13
        相关资源
        最近更新 更多