How can I get sqrt from Int.
I try so:
sqrt . fromInteger x
But get error with types compatibility.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Using
fromIntegral:both
IntandIntegerare instances ofIntegral:fromIntegral :: (Integral a, Num b) => a -> btakes yourInt(which is an instance ofIntegral) and "makes" it aNum.sqrt :: (Floating a) => a -> aexpects aFloating, andFloatinginherit fromFractional, which inherits fromNum, so you can safely pass tosqrtthe result offromIntegralI think that the classes diagram in Haskell Wikibook is quite useful in this cases.