3
votes

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?

1
The question is about a different package than the one asked about here, but the answer ought to be the same. I wonder if we should close this as a duplicate?Mark Seemann
The package name is arithmoi. See here for more details: stackoverflow.com/a/48855060/126014Mark Seemann
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
Cabal deals with packages, a package is a collection of modules. Math.NumberTheory is a module.Willem Van Onsem

1 Answers

0
votes

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