Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

haskell

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.

like image 695
mc.robin Avatar asked Jul 26 '17 04:07

mc.robin


1 Answers

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
like image 89
Koterpillar Avatar answered Sep 30 '22 06:09

Koterpillar