Haskell warning

I have written the code (I’m new to haskell, very new) and cant solve the warning problem

funk ::  Num a => a -> a
funk a = a + 10 
main :: IO()
main = print (funk 10 )

Warning:

Warnings: 1

  /home/anmnv/Desktop/qqq.hs: line 4, column 8:
    Warning: • Defaulting the following constraints to type ‘Integer’
    (Show a0) arising from a use of ‘print’ at qqq.hs:4:8-23
    (Num a0) arising from a use of ‘funk’ at qqq.hs:4:15-21
• In the expression: print (funk 10)
  In an equation for ‘main’: main = print (funk 10)

any help appreciated, thanks

>Solution :

It simply says that you did not specify the type for 10. It can strictly speaking by any type that is an member of the Num typeclass, but the compiler uses defaulting rules, and thus picks an Integer.

You can give Haskell a type constraint to determine the type of 10, for example:

funk :: Num a => a -> a
funk = (+ 10)

main :: IO ()
main = print (funk (10 :: Integer))

Leave a Reply