I can't seem to write a simple haskell function that gets an Either
input and use it. Here is what I wrote:
$ cat main.hs
module Main( main ) where
-- myAtoi :: Either String Int -> Int
myAtoi :: Int -> Int
myAtoi _ = 700
main :: IO ()
main = do
print(myAtoi(8))
And this obviously works fine:
$ ghc main.hs -o main
$ ./main
700
But when I remove the comment and use the first signature I get the following error:
[1 of 1] Compiling Main ( main.hs, main.o )
main.hs:9:14: error:
• No instance for (Num (Either String Int))
arising from the literal ‘8’
• In the first argument of ‘myAtoi’, namely ‘(8)’
In the first argument of ‘print’, namely ‘(myAtoi (8))’
In a stmt of a 'do' block: print (myAtoi (8))