以下函数编译并工作:
shares :: Maybe (Int, L.ByteString) -> Maybe Int
shares a =
case a of
Nothing -> Nothing
Just (x, y) -> Just x
但是当以以下形式重写时:
shares :: Maybe (Int, L.ByteString) -> Maybe Int
shares Nothing = Nothing
shares Just (x, y) = Just x
我收到错误
Equations for ‘shares’ have different numbers of arguments
我认为本质上是一样的。
在 Haskell 中,函数的参数用空格分隔。因此,最后一个方程有两个参数:a -> Maybe a
型的Just
和(Int, L.ByteString)
型的(x, y)
。由于你想要一个参数,它应该改为:
shares (Just (x, y)) = Just x