以下函数编译和工作:
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)
我认为它基本上是一样的.
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) 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 ×3