Import errors from a very simple program

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Import errors from a very simple program

John Sturdy
Hi,

I'm right at the start of learning Haskell, and I decided to jump from reading LYAH to writing a simple real-world program.

It's based very closely on https://github.com/haskell-hvr/cassava/blob/master/examples/NamedBasedGeneric.hs (I removed the bit that constructs the test file, as I already have a file), and I've done "cabal install cassava", first as root, and then when I first go the error, as myself using the sandbox (which didn't change the output).  I first tried this with running ghc directly, and then followed the instructions on https://wiki.haskell.org/How_to_write_a_Haskell_program, and all these get the same errors:

Main.hs:4:1: error:
    Could not find module ‘Data.Csv’
    Locations searched:
      Data/Csv.hs
      Data/Csv.lhs
      Data/Csv.hsig
      Data/Csv.lhsig
  |
4 | import Data.Csv
  | ^^^^^^^^^^^^^^^

Main.hs:6:1: error:
    Could not find module ‘Data.Vector’
    Perhaps you meant Data.Functor (from base-4.11.1.0)
    Locations searched:
      Data/Vector.hs
      Data/Vector.lhs
      Data/Vector.hsig
      Data/Vector.lhsig
  |
6 | import qualified Data.Vector as V
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I don't understand the connection between the name "cassava" and "Data/Csv", although looking around in the directories that have been produced, I see that Data/Csv is within the cassava directories.   I'd like not only to know how to fix this,  but also a pointer for what I should look at to understand what is going on.

This is on a Debian system.

thanks,

__John (completely new to Haskell, experienced in C, Lisp, Python and others, if that helps to pitch the level of answers)


_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Import errors from a very simple program

Francesco Ariis
Hello John,

On Thu, Sep 26, 2019 at 02:53:23PM +0100, John Sturdy wrote:
> Hi,
>
> I'm right at the start of learning Haskell, and I decided to jump from
> reading LYAH to writing a simple real-world program.
>
> It's based very closely on
> https://github.com/haskell-hvr/cassava/blob/master/examples/NamedBasedGeneric.hs

Cabalising a small project is one way to do it (and a useful skill
to learn, too):

    cd ~/somefolder
    wget -O Main.hs https://raw.githubusercontent.com/haskell-hvr/cassava/master/examples/NamedBasedGeneric.hs
    cabal init --is-executable --dependency=base --dependency=bytestring --dependency=vector --dependency=text --dependency=cassava
        # many questions! There is a non-interactive option.
    cabal new-repl
        # ghci repl for your project
    λ> main

Bingo!
Read the generated .cabal file to learn more on how it works
Does this help?
-F
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Import errors from a very simple program

Daniel Trstenjak-2
In reply to this post by John Sturdy
Hi John,

if I'm understanding you correctly, you're installing packages by hand
with 'cabal install' and then calling 'ghc' by hand for your source file.

'ghc' won't automatically use the packages you've installed with 'cabal install',
but you've to add them to the 'ghc' call. Your compile error seems to indicate,
that the 'cassava' and 'vector' packages haven't been given to the 'ghc' call.

But most likely it isn't worth the hassle doing this and it is a lot
easier to just create a default cabal file with 'cabal init'. Then you
can add the 'cassava' and 'vector' packages as dependencies and build
the packages and your source file with 'cabal new-build'.

Greetings,
Daniel
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Import errors from a very simple program

John Sturdy
On Thu, Sep 26, 2019 at 3:18 PM Daniel Trstenjak <[hidden email]> wrote:
Hi John,

'ghc' won't automatically use the packages you've installed with 'cabal install',
but you've to add them to the 'ghc' call.

Thanks, that'll be the key to what's going on.  I had assumed that installed packages would be automatically available for "import", as they are in Python.  (The program I'm writing has the same functionality as a Python program I had written earlier, which probably biased me to thinking that way.)

__John


_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners