mightybyte / monad-challenges

A set of challenges for jump starting your understanding of monads.
http://mightybyte.github.io/monad-challenges/
Other
324 stars 76 forks source link

Attempted to follow the "Getting Started" instructions, couldn't successfully import MCPrelude. #81

Open derifatives opened 3 years ago

derifatives commented 3 years ago

I followed the "Getting Started" instructions at https://mightybyte.github.io/monad-challenges/. The cabal install ran for a long time (maybe 20 minutes? I wandered off) but seemed to complete successfully. However, trying to ghci a simple toy file failed to import the prelude:

rif@rifo1:~/tmp/mc/monad-challenges/monad-challenges-code$ cat Set1.hs
{-# LANGUAGE MonadComprehensions #-}
{-# LANGUAGE RebindableSyntax  #-}

module Set1 where

import MCPrelude

fiveRands:: [Integer]
fiveRands = [3, 4, 5]

rif@rifo1:~/tmp/mc/monad-challenges/monad-challenges-code$ ghci Set1.hs
GHCi, version 8.8.4: https://www.haskell.org/ghc/  :? for help
[1 of 1] Compiling Set1             ( Set1.hs, interpreted )

Set1.hs:6:1: error:
    Could not find module ‘MCPrelude’
    Perhaps you meant Prelude (from base-4.13.0.0)
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
  |
6 | import MCPrelude
  | ^^^^^^^^^^^^^^^^
Failed, no modules loaded.
Prelude> 

Is there maybe some missing piece of newbie instructions here? Do I have to somehow add MCPrelude to a path or something?

derifatives commented 3 years ago

It's also possible I've done something previously that messed up my system. I don't really understand Haskell install or what is / isn't hermetic.

georgefst commented 3 years ago

I was just about to open an issue about this. The problem is that the guide uses the old-fashioned way of installing libraries. Cabal has changed a lot in the last few years.

I think the simplest solution (assuming that you're using Cabal 3+, check with cabal -V) would be to create a folder for the Haskell source files you're going to write, then run cabal install --package-env /PATH_TO_YOUR_FOLDER --lib instead of just cabal install. This will create a file called something like .ghc.environment.x86_64-darwin-8.10.3, which will tell calls to ghc and ghci from that folder, where to find MCPrelude.

@mightybyte Should I open a PR modifying/expanding the instructions, or do you have a preferred solution?

derifatives commented 3 years ago

This does seem to work, thanks!

georgefst commented 3 years ago

That's a bizarre error @Aster89.

Is there any chance you've tampered with your ghci? Do you have another ghci on your PATH, or have you set an alias? What happens if you run which ghci?

Aster89 commented 3 years ago

@georgefst , I had an alias :/