小编mc.*_*bin的帖子

为什么我得到"具有不同数量的参数的方程式"消息?

以下函数编译和工作:

shares :: Maybe (Int, L.ByteString) -> Maybe Int                                                                                                                                                            
shares a =                                                                                                                                                                                                  
    case a of                                                                                                                                                                                               
        Nothing        -> Nothing                                                                                                                                                                           
        Just (x, y)    -> Just x
Run Code Online (Sandbox Code Playgroud)

但是当以下面的形式重写时:

shares :: Maybe (Int, L.ByteString) -> Maybe Int                                                                                                                                                            
shares Nothing = Nothing                                                                                                                                                                                    
shares Just (x, y) = Just x
Run Code Online (Sandbox Code Playgroud)

我收到错误

Equations for ‘shares’ have different numbers of arguments
Run Code Online (Sandbox Code Playgroud)

我认为它基本上是一样的.

haskell

2
推荐指数
1
解决办法
831
查看次数

混淆了haskell中的复合函数

let f = show.sum.map read.words
f "1 2"
Run Code Online (Sandbox Code Playgroud)

这行得通.

show.sum.map read.words "1 2"
Run Code Online (Sandbox Code Playgroud)

我收到错误:

<interactive>:19:19:
    Couldn't match expected type ‘a -> [String]’
                with actual type ‘[String]’
    Relevant bindings include
      it :: a -> String (bound at <interactive>:19:1)
    Possible cause: ‘words’ is applied to too many arguments
    In the second argument of ‘(.)’, namely ‘words "1 2"’
    In the second argument of ‘(.)’, namely ‘map read . words "1 2"’
Prelude> :t show.sum.map
show.sum.map
  :: (Num [b], Show b, Foldable ((->) …
Run Code Online (Sandbox Code Playgroud)

haskell

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

混淆了复合函数与haskell中的map

 let f = map tail.lines
 f "fsdaf\nfdsf\n"
Run Code Online (Sandbox Code Playgroud)

它为什么有效?

let f = map tail.tail.lines
f "fasdf\nfasdfdsfd\n"
Run Code Online (Sandbox Code Playgroud)

我得到结果:

["asdfdsfd"]
let f = map (tail.tail).lines
f "fasdf\nfasdfdsfd\n"
Run Code Online (Sandbox Code Playgroud)

我得到结果:

["sdf","sdfdsfd"]
Run Code Online (Sandbox Code Playgroud)

我想知道haskell如何解析上面的代码.

haskell

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

标签 统计

haskell ×3