Home > Enterprise >  How to use integerFromInt from GHC.Num.Integer in Haskell
How to use integerFromInt from GHC.Num.Integer in Haskell

Time:12-27

I'm new in Haskell. I'm trying to use integerFromInt from GHC.Num.Integer. I tried to write integerFromInt without import GHC.Num.Integer and I got
Variable not in scope: integerFromInt :: Int -> Integer

I tried to write integerFromInt with import GHC.Num.Integer and I got

  Could not find module ‘GHC.Num.Integer’
    Perhaps you meant GHC.Integer (from integer-gmp-1.0.3.0)

I think I have to add something to cabal file, but I don't know what

CodePudding user response:

If you must use exactly that function, then its documentation indicates that it comes from the ghc-bignum package. You can see this in the URL or by scrolling to the top of the page and looking in the top left. So you would need to add build-depends: ghc-bignum, preferably with a version constraint like build-depends: ghc-bignum ^>=1.2 or whatever, to the appropriate component(s) in your cabal file.

...but in most cases, the correct answer is to use toInteger (or fromIntegral) instead, both available without imports and without adding anything to your cabal file.

  • Related