'Haskell - what type declaration would I use for this function? [duplicate]

What would the type declaration be for this Haskell function definition?

guessMe1 x y z | x == y = x + z
               | y == z = y + z
               | otherwise = x + y + z


Solution 1:[1]

You can let this task to Haskell compiler like this:

ghci
GHCi, version 8.6.5: http://www.haskell.org/ghc/  :? for help
Prelude> :{
Prelude| guessMe1 x y z | x == y = x + z
Prelude|                | y == z = y + z
Prelude|                | otherwise = x + y + z
Prelude| :}
Prelude> :type guessMe1
guessMe1 :: (Eq a, Num a) => a -> a -> a -> a
Prelude> 

The most usefull command is :?.
Then you can see:

...
:{\n ..lines.. \n:}\n       multiline command
...
:type <expr>                show the type of <expr>
...

Answer is:

guessMe1 :: (Eq a, Num a) => a -> a -> a -> a

This means that the first second and third parameters must have a defined equivalence and must be a number. Both the parameters and the result must have the same type.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1