mc.robin
mc.robin

Reputation: 179

Why am I getting the "Equations for ... have different numbers of arguments" message?

The following function compiles and works:

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

But when rewritten in the following form:

shares :: Maybe (Int, L.ByteString) -> Maybe Int                                                                                                                                                            
shares Nothing = Nothing                                                                                                                                                                                    
shares Just (x, y) = Just x

I get errors

Equations for ‘shares’ have different numbers of arguments

I think it's same essentially.

Upvotes: 5

Views: 4523

Answers (1)

Koterpillar
Koterpillar

Reputation: 8104

In Haskell, arguments to function are separated by spaces. Therefore, the last equation has two arguments: Just of type a -> Maybe a and (x, y) of type (Int, L.ByteString). Since you want one argument, it should instead read:

shares (Just (x, y)) = Just x

Upvotes: 8

Related Questions