1
votes

This must be very simple; but why this error:

PS C:\Users\guthrie\Desktop> cabal install --lib timeit
Resolving dependencies...
Up to date
PS C:\Users\guthrie\Desktop> ghci
GHCi, version 8.10.2: https://www.haskell.org/ghc/  :? for help
Prelude> :m System.TimeIt

<no location info>: error:
    Could not find module `System.TimeIt'
    Perhaps you meant System.Timeout (from base-4.14.1.0)
Prelude>
Leaving GHCi.

Hackage shows System.TimeIt as being defined in timeit-2.0, which is what cabal installed.

PS C:\Users\guthrie\Desktop> cabal install timeit
Resolving dependencies...
Build profile: -w ghc-8.10.2 -O1
In order, the following will be built (use -v for more details):
 - timeit-2.0 (lib) (requires download & build)
Downloading  timeit-2.0
Downloaded   timeit-2.0
Starting     timeit-2.0 (lib)
Building     timeit-2.0 (lib)
Installing   timeit-2.0 (lib)
Completed    timeit-2.0 (lib)

Checking again:

PS C:\Users\guthrie\Desktop> cabal install --lib timeit
Resolving dependencies...
Up to date

But trying to check on it from cabal info::

PS C:\Users\guthrie\Desktop> cabal info timeit
* timeit           (library)
    Synopsis:      Time monadic computations with an IO base.
    Versions available: 0.9.0.0, 1.0.0.0, 2.0
    Versions installed: [ Not installed ]
    Homepage:      https://github.com/merijn/timeit
    Bug reports:   https://github.com/merijn/timeit/issues
    Description:   A simple wrapper to show the used CPU time of monadic
                   computation with an IO base.
    Category:      System
    License:       BSD3
    Author:        Lennart Augustsson
    Maintainer:    Merijn Verstraaten <[email protected]>, Lennart Augustsson
    Source repo:   ssh://github.com:merijn/timeit.git
    Dependencies:  base >=3 && <5, transformers >=0.2 && <0.6
    Cached:        Yes
    Modules:
        System.TimeIt

So it reports: "Not installed". Same problem with criterion (Criterion.Main).

I see a note from 2/2020; that if a package is installed without the --lib option,

It does add the library to the package db in this case but does not add it to the default environment. (*https://github.com/haskell/cabal/issues/6262#issuecomment-589843722)

So I repeated the install with this option, no effect - just reported "Up to date".

That same link gave a solution (work-around?) to use instead cabal v1-install, which does work. But what would be the recommended simple solution to be able just to use ghci for testing small codes? Forced migration to stack, with local sandboxed and copies of everything for every small test?

Since I am only doing very simple short tests of examples, I was not creating a sandbox for each, and do not have a .cabal file, are those now necessary?!

(cabal 3.2.0.o, ghc 8.10.2, Windows 10)

1
Use a local environment: stackoverflow.com/questions/63837574/…danidiaz
Yes, I've seen that - but the question was if using the -lib option would (should) work, and else it is accurate that the prior (cabal install, ghci) usage is just now gone. That note says to create a separate directory and environment for every .hs file, not so convenient when I have a folder with 80-90 simple one file.hs samples. An additional comment there says that using the --lib on cabal install, should work with a default global repository, which it didn't for me. I'll retest this.guthrie
The default global repository not working might be a bug. In theory it should work. You don't need an environment for each hs file, a single environment in the folder with the dependencies for all the files will be enough. You can also specify the location of the environment file with the GHC_ENVIRONMENT environment variable downloads.haskell.org/ghc/latest/docs/html/users_guide/…danidiaz
Yes - thanks. But that also couples the code.hs files to a particular directory. I don't have the GHC_ENVIRONMENT variable set, will see if pointing it to a global repository helps. But as you notes, the legacy "cabal install --lib; ghc" should work.guthrie
I have reproduced the problem with the default environment on Windows and opened a GHC issue: gitlab.haskell.org/ghc/ghc/-/issues/19286danidiaz

1 Answers

0
votes

I strongly recommend that you don't try to use ghc and ghci directly but instead use cabal. If you want to quickly play around with timeit in the REPL then use

cabal v2-repl --build-depends timeit

If you want to do anything more complicated then create a (perhaps temporary) project and add timeit as a dependency:

$ mkdir my-temporary-package
$ cd my-temporary-package
$ cabal init

Edit my-temporary-package.cabal to change

build-depends:       base >=... && <...

to

build-depends:       base, timeit

(The constraints on base are going to cause you more harm than good for a quick exploratory project. You can add them back later if it becomes necessary.) Then

$ cabal v2-repl

will get you a REPL with timeit available.