Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting Int to Integer [duplicate]

Possible Duplicate:
Haskell Error: Couldn't match expected type Integer' against inferred typeInt'

How can I convert Int to Integer in Haskell?

like image 623
marco Avatar asked Oct 31 '10 03:10

marco


People also ask

How do you convert int to Integer?

Convert Int to Integer Using the Integer. valueOf() Method in Java. This is another that we can use to convert an int to an Integer in Java. Here, we used valueOf() method of the Integer class.

Can you turn an int into a double?

We can convert int value to Double object by instantiating Double class or calling Double. valueOf() method.

Which of the following converts an int to an Integer object?

Use Integer constructor to convert int primitive type to Integer object.

How do you convert a number to an Integer in Haskell?

There are special cases for converting from Integer s: fromInteger :: Num a => Integer -> a. as well as for converting to Integer s: toInteger:: Integral a => a -> Integer.


2 Answers

There is a toInteger function you can use.

like image 132
sth Avatar answered Oct 12 '22 12:10

sth


fromIntegral is a good generic way to convert any Integral value into any other Integeral. But as sth said, toInteger works for the case of converting specifically to an Integer.

like image 41
Michael Snoyman Avatar answered Oct 12 '22 13:10

Michael Snoyman