Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading