2

I would like to use Math.NumberTheory.Moduli.Class in my Haskell program. It doesn't seem to be included in Prelude since when I try to use it in GHCI

> (3 :: Mod 5) + (4 :: Mod 5)

we have Not in scope: type constructor or class ‘Mod’. I also can't seem to import it into GHCI since none of the following work

> import Math.NumberTheory.Moduli.Class
> import Math.NumberTheory.Moduli
> import Math.NumberTheory

because "Could not find module". Finally,

cabal install Math.NumberTheory

seems to have no knowledge of any such package names "Math". Moreover, I can't figure out how to use any of the packages in Math.NumberTheory. How does one import these into a Haskell program?

Jon Deaton
  • 3,943
  • 6
  • 28
  • 41
  • 1
    The question is about a different package than the one [asked about here](https://stackoverflow.com/a/59225974/126014), but the answer ought to be the same. I wonder if we should close this as a duplicate? – Mark Seemann Dec 16 '19 at 07:38
  • 2
    The package name is `arithmoi`. See here for more details: https://stackoverflow.com/a/48855060/126014 – Mark Seemann Dec 16 '19 at 07:39
  • 1
    There are a lot of concepts that you are misunderstanding/not aware of here, and I do not have time to write a full answer. For helpfulness's sake, you should be able to incant `cabal v2-repl -b arithmoi`, and then import your desired modules. – HTNW Dec 16 '19 at 08:08
  • 3
    Cabal deals with *packages*, a package is a collection of *modules*. `Math.NumberTheory` is a *module*. – Willem Van Onsem Dec 16 '19 at 08:34

1 Answers1

0

It doesn't seem to be included in Prelude

Prelude is a module, not a package, and thus can not include other modules. You probably mean "base".

cabal install Math.NumberTheory seems to have no knowledge of any such package names "Math"

Because that is a module name, not a package which is a collection of modules (roughly). You need to tell cabal to install the package not the module.

Try instead:

cabal install arithmoi
ghci
import Math.NumberTheory.Moduli.Class

Or as a project-in-a-file:

$ cat so.hs
#!/usr/bin/env cabal
{- cabal:
        build-depends: base, arithmoi
-}

module Main where

import Math.NumberTheory.Moduli.Class

main :: IO ()
main = return ()
$ chmod +x so.hs ; ./so.hs 2>/dev/null 1>&2 ; echo $?
0
Thomas M. DuBuisson
  • 64,245
  • 7
  • 109
  • 166