0

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

Max Osad
  • 27
  • 5
  • 1
    I don't think there is a `integerFromInt` function. You have `fromIntegral` and `fromInteger`, iirc. – user1984 Dec 26 '21 at 00:04
  • `integerFromInt` is a function of `ghc-bignum` package. Instead, `toInteger` should work. – Abastro Dec 26 '21 at 00:06
  • I see @Abastro thank you for letting me know – user1984 Dec 26 '21 at 00:07
  • In general, stay away from the `GHC.Something` modules -- they are mostly meant for low-level primitives you are not supposed to call directly. – chi Dec 26 '21 at 00:12

1 Answers1

0

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.

Daniel Wagner
  • 145,880
  • 9
  • 220
  • 380