2

I made 3 Haskell scripts in a folder, and they import Text.Printf, Data.Char, Data.List, and System.Random:

HaskellList.hs

import Data.List
import System.Random
main :: IO ()
main = do
    let vb = [50, 40, 30, 20, 10, 0]
    let vbEli = head vb
    let vbElm = vb !! 2
    let vbElf = last vb
    let vbIni = elemIndex 30 vb
    let vbInf = maybe (-1) (\i -> length vb - i - 1) (elemIndex 30 (reverse vb))
    let vbLen = length vb
    let vbMin = minimum vb
    let vbMax = maximum vb
    let vbSum = sum vb
    let vbAve = fromIntegral (sum vb) / fromIntegral (length vb)
    let vbSub = take 4 (drop 1 vb)
    let vbFil = filter (\n -> n `mod` 4 == 0) vb
    let vbMap = map (\n -> n * n) vb
    let vbSuf = shuffle' vb (length vb) gen
    let vbRev = reverse vb
    let vbAsc = sort vb
    let vbDsc = sortBy (flip compare) vb
    mapM_ putStrLn [show vbEli, show vbElm, show vbElf, show vbIni, show vbInf, show vbLen, show vbMin, show vbMax, show vbSum, show vbAve,
                    show vbSub, show vbFil, show vbMap, show vbSuf, show vbRev, show vbAsc, show vbDsc]

HaskellNumber.hs

import Text.Printf

main :: IO ()
main = do
    let vb :: Int = 4
    let vbPo2 :: Double = 2 ** fromIntegral vb
    let vbPoe :: Double = exp (fromIntegral vb)
    let vbRo2 :: Double = sqrt (fromIntegral vb)
    let vbRoe :: Double = fromIntegral vb ** (1 / exp 1)
    let vbLo2 :: Double = logBase 2 (fromIntegral vb)
    let vbLoe :: Double = log (fromIntegral vb)
    let vbStr = show vb
    let vbPad :: String = printf "%06d" vb
    mapM_ putStrLn [show vbPo2, show vbPoe, show vbRo2, show vbRoe, show vbLo2, show vbLoe,
                    show vbStr, show vbPad]

HaskellString.hs

import Data.Char (toLower, toUpper)
import Data.List (findIndex, intercalate, isInfixOf, tails)
main :: IO ()
main = do
    let vb = "Yasuraoka Hanabi"
    let vbEli = head vb
    let vbElm = vb !! 7
    let vbElf = last vb
    let vbIni = maybe (-1) id (findIndex ((map toLower "NA") `isInfixOf`) (tails (map toLower vb)))
    let vbInf = maybe (-1) id (findIndex ((map toLower "NA") `isInfixOf`) (reverse (tails (map toLower vb))))
    let vbLen = length vb
    let vbCon = vb ++ " is best girl!"
    let vbSub = take 4 (drop 10 vb)
    let vbLoc = map toLower vb
    let vbUpc = map toUpper vb
    let vbRep = intercalate "-" (words vb)
    let vbSpl = words vb
    mapM_ putStrLn [
        show vbEli, show vbElm, show vbElf, show vbIni, show vbInf, show vbLen,
        show vbCon, show vbSub, show vbLoc, show vbUpc, show vbRep,
        show vbSpl]

The problem is all of the modules can't be imported. When I run them, they always return error with messages that look like this (this one is with Data.List):

    Could not load module `Data.List'
    It is a member of the hidden package `base-4.18.0.0'.
    You can run `:set -package base' to expose it.
    (Note: this unloads all the modules in the current scope.)
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
  |
1 | import Data.List

  | ^^^^^^^^^^^^^^^^

I tried to remove the imports and code lines that need it, and the result is like this:

    Could not load module `Prelude'
    It is a member of the hidden package `base-4.18.0.0'.
    You can run `:set -package base' to expose it.
    (Note: this unloads all the modules in the current scope.)
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
  |
1 | main :: IO ()

  | ^

Before Haskell is like this, I could run Haskell files well, except I couldn't import System.Random, so I needed to install it. At some point between then and now:

  1. I updated cabal to version 3.10.1.0.
  2. Before I could update cabal, my attempts at updating it always end in error. It might have something to do with past Haskell installation where 1 in 4 packages failed to be installed (it was ghc — I tried to install it alone and it ended up being installed in C:\tools). So I force reinstalled Haskell and the 4th package was finally installed — and cabal could be updated.

Some contexts that might be useful:

  1. I use Windows 11.
  2. The codes are run on Visual Studio Code.
  3. I didn't make any project, it's just those 3 files in one folder.

Your help will be appreciated.

Prido1024
  • 51
  • 3

1 Answers1

0

Finally I was able to solve this problem. I originally installed Haskell's cabal, GHC, and other components from chocolatey, so I tried uninstalling them and reinstalling them using GHCup.

Note that the cabal (version 3.6.2.0) was not runnable at first because of “cannot parse at nix” error. After I added 2-space indent before nix: disable, it could finally run albeit with warnings about nix being unrecognized. Might fix this later.

But overall, I can run Haskell well like before.

Prido1024
  • 51
  • 3