Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Haskell ignore Ints vs. Integers?

Tags:

haskell

I have a program that uses both Int and Integer, because a few of the functions return results that are quite large. I'm tired of having to use fromIntegral everywhere and I was wondering if there's a way to get Haskell to ignore the distinction between Int and Integer upon compilation.

like image 958
rotskoff Avatar asked Apr 22 '12 22:04

rotskoff


People also ask

What is the difference between an Int and an integer in Haskell?

What's the difference between Integer and Int ? Integer can represent arbitrarily large integers, up to using all of the storage on your machine. Int can only represent integers in a finite range.

What does Int -> Int mean Haskell?

It states that this function is of type Int -> Int , that is to say, it takes an integer as its argument and it returns an integer as its value.

How are integers defined in Haskell?

In practice, Int is defined by the compiler to be equivalent to a 32-bit integer value. The reason for this is that Int can be optimized in certain ways that a machine word cannot. Pointer tagging is important for Haskell performance, and so implementations are free to use some number of bits.


1 Answers

Solution: remove the Ints from your program and just use all Integers. As noted by geekosaur, you can use the generic functions from Data.List (e.g. genericLength). If you provide us with your specific program code, then we could give more specific suggestions.

like image 200
Dan Burton Avatar answered Oct 19 '22 06:10

Dan Burton