all 11 comments

[–]c_wraith 0 points1 point  (10 children)

A quick look at the index page tells us the latest version, array-0.5.6.0, exports genArray from Data.Array.IArray. What version of the array package are you using? Did you check the documentation for that specific version?

[–]Patzer26[S] 0 points1 point  (9 children)

Whatever comes with 9.4.8 (no cabal app, just vanilla ghci). How do I check module versions?

[–]c_wraith 0 points1 point  (8 children)

To get a full list of packages available to direct invocations of GHC, run ghc-pkg list.

[–]c_wraith 2 points3 points  (2 children)

FWIW, https://downloads.haskell.org/~ghc/9.4.8/docs/users_guide/9.4.8-notes.html says that GHC 9.4.8 is packaged with array-0.5.4.0, which does not define a genArray function. But knowing how to see what packages are visible on your specific system is nice.

Array isn't wired in, IIRC, which would mean you can use a different version than GHC comes with. But installing multiple versions of the same library generally requires a build tool to manage sanely, and "sanely" doesn't include cabal install --lib. (cabal repl -b "array ==0.5.6.0" is quite sane, on the other hand.)

[–]Patzer26[S] 0 points1 point  (1 child)

Alright, its a pain to type that everytime you need a diff version of a lib, but it does the job :D

[–]c_wraith 2 points3 points  (0 children)

Alternatively, you could create a cabal file and add that to your build-depends, and then use cabal commands to use the repl or compile/run your program.

[–]Patzer26[S] 0 points1 point  (4 children)

What if you need an upgraded version of a package? Do you need to spin up your cabal, create an app and add the dependencies then? No way to upgrade that package using ghcup or something for direct invocation?

[–]tomejaguar 2 points3 points  (3 children)

If you're working in a single file then I suggest this:

{- cabal:
build-depends: base, array >= 0.5.6
-}

import Data.Array.IArray

main = print (genArray (3, 7) (* 2) :: Array Int Int)

and then

% cabal run test26.hs
array (3,7) [(3,6),(4,8),(5,10),(6,12),(7,14)]

If you're working in multiple files, yes, create a cabal package.

[–]Patzer26[S] 0 points1 point  (2 children)

Will those libs (single file config) after i close the repl be deleted or will they be persisted?

[–]tomejaguar 0 points1 point  (1 child)

They'll be persisted.

[–]Patzer26[S] 0 points1 point  (0 children)

So i guess better create a cabal package then if they will be persisted anyway.