Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: Combining IO and Either function to "EitherT e IO a"
(Kim-Ee Yeoh)
2. Re: Using GHCi, import submodule that needs to import
another submodule? (David McBride)
3. Re: Using GHCi, import submodule that needs to import
another submodule? (James Toll)
4. Re: Using GHCi, import submodule that needs to import
another submodule? (Brent Yorgey)
5. Re: Using GHCi, import submodule that needs to import
another submodule? (James Toll)
6. Re: Using GHCi, import submodule that needs to import
another submodule? (Daniel Trstenjak)
7. Re: Using GHCi, import submodule that needs to import
another submodule? (James Toll)
----------------------------------------------------------------------
Message: 1
Date: Thu, 6 Mar 2014 01:18:55 +0700
From: Kim-Ee Yeoh <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Combining IO and Either function to
"EitherT e IO a"
Message-ID:
<CAPY+ZdQAv0iWWMAHYTVedKKntep6mq=yc0e9zhqt4hurqfn...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
On Thu, Mar 6, 2014 at 12:49 AM, Nathan H?sken <[email protected]>wrote:
> Mmh, I might not have used haskell terminology correctly. Its a function,
> in the sense of a function of an imperative language ...
Yes, you could model IO String in C as a function taking void and returning
a pointer to char.
Calling an IO String a Haskell function would confuse a lot of people.
-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20140306/82c2bab8/attachment-0001.html>
------------------------------
Message: 2
Date: Wed, 5 Mar 2014 13:25:48 -0500
From: David McBride <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Using GHCi, import submodule that
needs to import another submodule?
Message-ID:
<can+tr435iw4uxt9_h0kbuxfvnzoff+65675gyk9dlnqje1j...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
If you want a source file to have a module Geometry.Cuboid, it should be in
a directory named Geometry and the file will have the name of Cuboid.hs.
In order to load that you have to start ghci in the directory that contains
the Geometry directory, not in the one that contains the source file.
So cd .., ghci Geometry/Cuboid.hs
On Wed, Mar 5, 2014 at 1:07 PM, James Toll <[email protected]> wrote:
> Hi,
>
> I am trying to figure out how to import one submodule from a hierarchical
> module in GHCi. For example, at the end of Chapter 6 of LYAHFGG (page
> 106-107), there's an example of a hierarchical module. Or at the bottom of
> this page, http://learnyouahaskell.com/modules
>
> If I recreate that module on my system and try to import, this is the
> output:
>
> [~/Geometry]$ ls
> Cube.hs Cuboid.hs Sphere.hs
> [~/Geometry]$ ghci
> GHCi, version 7.6.3: http://www.haskell.org/ghc/ :? for help
> Loading package ghc-prim ... linking ... done.
> Loading package integer-gmp ... linking ... done.
> Loading package base ... linking ... done.
> Prelude> import Geometry.Sphere
>
> <no location info>:
> Could not find module `Geometry.Sphere'
> It is not a module in the current program, or in any known package.
> Prelude> :set -iGeometry
> Prelude> import Geometry.Sphere
>
> <no location info>:
> Could not find module `Geometry.Sphere'
> It is not a module in the current program, or in any known package.
> Prelude> :load Sphere
> [1 of 1] Compiling Geometry.Sphere ( Sphere.hs, interpreted )
> Ok, modules loaded: Geometry.Sphere.
> *Geometry.Sphere> :load Cube
>
> Cube.hs:6:18:
> Could not find module `Geometry.Cuboid'
> Use -v to see a list of the files searched for.
> Failed, modules loaded: none.
> Prelude> :load Cuboid
> [1 of 1] Compiling Geometry.Cuboid ( Cuboid.hs, interpreted )
> Ok, modules loaded: Geometry.Cuboid.
> *Geometry.Cuboid> :load Cube
>
> Cube.hs:6:18:
> Could not find module `Geometry.Cuboid'
> Use -v to see a list of the files searched for.
> Failed, modules loaded: none.
> Prelude>
>
>
> So I can't just "import Geometry.Sphere", and I tried setting -i, but that
> doesn't seem to help. Instead I have to ":load Sphere". Fine, but then
> when I try to ":load Cube", it fails because of the line in Cube.hs that
> imports Geometry.Cuboid. Even if I load Geometry.Cuboid first and then try
> to load Geometry.Cube, it still fails.
>
> So, in GHCi, how do I successfully import a submodule that needs to import
> some other submodule in the module?
>
> Thanks,
>
>
> James
>
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20140305/eed84bb9/attachment-0001.html>
------------------------------
Message: 3
Date: Wed, 5 Mar 2014 12:39:01 -0600
From: James Toll <[email protected]>
To: haskell-beginners <[email protected]>
Subject: Re: [Haskell-beginners] Using GHCi, import submodule that
needs to import another submodule?
Message-ID: <[email protected]>
Content-Type: text/plain; charset=windows-1252
On Mar 5, 2014, at 12:17 PM, Daniel Trstenjak wrote:
> Hi James,
>
> On Wed, Mar 05, 2014 at 12:07:33PM -0600, James Toll wrote:
>> So, in GHCi, how do I successfully import a submodule that needs to import
>> some other submodule in the module?
>
> [~/Geometry]$ cd ..
> [~]$ ghci
>> import Geometry.Sphere
Hi Daniel,
Thank you for your suggestion. It appears that your suggestion partially works.
Picking up from where I left off previously:
Prelude> :q
Leaving GHCi.
[~/Geometry]$ cd ..
[~/]$ ls
Geometry/ clang-xcode5-wrapper.hs test.hs
[~/]$ ghci
GHCi, version 7.6.3: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> import Geometry.Sphere
<no location info>:
Could not find module `Geometry.Sphere'
It is not a module in the current program, or in any known package.
Prelude> :load Sphere
<command line>:
Could not find module `Sphere'
Use -v to see a list of the files searched for.
Failed, modules loaded: none.
Prelude> :load Geometry.Sphere
[1 of 1] Compiling Geometry.Sphere ( Geometry/Sphere.hs, interpreted )
Ok, modules loaded: Geometry.Sphere.
*Geometry.Sphere> :load Geometry.Cube
[1 of 2] Compiling Geometry.Cuboid ( Geometry/Cuboid.hs, interpreted )
[2 of 2] Compiling Geometry.Cube ( Geometry/Cube.hs, interpreted )
Ok, modules loaded: Geometry.Cube, Geometry.Cuboid.
*Geometry.Cube>
So import still does not work. But by trying ?:load" from the parent
directory, I was able to load Sphere, Cube and Cuboid. The problem is that it
appears that only one is available at a time (i.e. loading Cube displaces
Sphere). What?s more there is no way to do qualified imports.
Regards,
James
------------------------------
Message: 4
Date: Wed, 5 Mar 2014 13:47:48 -0500
From: Brent Yorgey <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Using GHCi, import submodule that
needs to import another submodule?
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Wed, Mar 05, 2014 at 12:39:01PM -0600, James Toll wrote:
> Prelude> :load Geometry.Sphere
> [1 of 1] Compiling Geometry.Sphere ( Geometry/Sphere.hs, interpreted )
> Ok, modules loaded: Geometry.Sphere.
> *Geometry.Sphere> :load Geometry.Cube
> [1 of 2] Compiling Geometry.Cuboid ( Geometry/Cuboid.hs, interpreted )
> [2 of 2] Compiling Geometry.Cube ( Geometry/Cube.hs, interpreted )
> Ok, modules loaded: Geometry.Cube, Geometry.Cuboid.
> *Geometry.Cube>
Use :add instead of :load for Geometry.Cube. :load loads the
specified module but forgets anything that was previously loaded.
:add loads a module without forgetting previously loaded things.
The differeces between :load, :add, and :module/import are somewhat
subtle and certainly confusing. You may find
http://www.haskell.org/ghc/docs/7.6.3/html/users_guide/interactive-evaluation.html#ghci-scope
helpful.
-Brent
------------------------------
Message: 5
Date: Wed, 5 Mar 2014 13:12:33 -0600
From: James Toll <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Using GHCi, import submodule that
needs to import another submodule?
Message-ID: <[email protected]>
Content-Type: text/plain; charset=windows-1252
On Mar 5, 2014, at 12:47 PM, Brent Yorgey wrote:
> On Wed, Mar 05, 2014 at 12:39:01PM -0600, James Toll wrote:
>> Prelude> :load Geometry.Sphere
>> [1 of 1] Compiling Geometry.Sphere ( Geometry/Sphere.hs, interpreted )
>> Ok, modules loaded: Geometry.Sphere.
>> *Geometry.Sphere> :load Geometry.Cube
>> [1 of 2] Compiling Geometry.Cuboid ( Geometry/Cuboid.hs, interpreted )
>> [2 of 2] Compiling Geometry.Cube ( Geometry/Cube.hs, interpreted )
>> Ok, modules loaded: Geometry.Cube, Geometry.Cuboid.
>> *Geometry.Cube>
>
> Use :add instead of :load for Geometry.Cube. :load loads the
> specified module but forgets anything that was previously loaded.
> :add loads a module without forgetting previously loaded things.
>
> The differeces between :load, :add, and :module/import are somewhat
> subtle and certainly confusing. You may find
>
>
> http://www.haskell.org/ghc/docs/7.6.3/html/users_guide/interactive-evaluation.html#ghci-scope
Thank you for the suggestion. I will read up on scope and try using add. But
what I would really prefer is to be able to import individual submodules in
GHCi using standard import syntax from the GHCi command line:
Prelude> import qualified Geometry.Sphere as Sphere
Is that not possible? LYAHFFG seems to imply that it is, and Daniel?s response
to this question seems to also suggest that it?s possible. Then I can control
how the functions in the submodule are referenced.
Thanks again,
James
------------------------------
Message: 6
Date: Wed, 5 Mar 2014 20:18:36 +0100
From: Daniel Trstenjak <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Using GHCi, import submodule that
needs to import another submodule?
Message-ID: <20140305191836.GA23005@machine>
Content-Type: text/plain; charset=utf-8
Hi James,
> So import still does not work. But by trying ?:load" from the parent
> directory, I was able to load Sphere, Cube and Cuboid. The problem is
> that it appears that only one is available at a time (i.e. loading
> Cube displaces Sphere). What?s more there is no way to do qualified
> imports.
Sorry about this one. 'import' depends on the available/installed ghc packages,
the given module name 'Geometry.Sphere' is looked up in these packages.
Calling 'ghc-pkg list' will give you a list of all packages.
If you don't have created and installed a package for your geometry
files, then ghci will not know them.
So calling ':load/:add' is the right thing here.
Greetings,
Daniel
------------------------------
Message: 7
Date: Wed, 5 Mar 2014 15:11:06 -0600
From: James Toll <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Using GHCi, import submodule that
needs to import another submodule?
Message-ID: <[email protected]>
Content-Type: text/plain; charset=windows-1252
On Mar 5, 2014, at 1:18 PM, Daniel Trstenjak wrote:
> Hi James,
>
>> So import still does not work. But by trying ?:load" from the parent
>> directory, I was able to load Sphere, Cube and Cuboid. The problem is
>> that it appears that only one is available at a time (i.e. loading
>> Cube displaces Sphere). What?s more there is no way to do qualified
>> imports.
>
> Sorry about this one. 'import' depends on the available/installed ghc
> packages,
> the given module name 'Geometry.Sphere' is looked up in these packages.
>
> Calling 'ghc-pkg list' will give you a list of all packages.
>
> If you don't have created and installed a package for your geometry
> files, then ghci will not know them.
>
> So calling ':load/:add' is the right thing here.
Daniel et al.,
Thank you for the clarification. No worries. I appreciate you taking the time
to respond to my question.
One observation I could make as a beginner is that I wish the documentation
made a better distinction between packages and modules. I suppose the
ambiguity from my standpoint (please correct me if I?m wrong) is that all
packages are, or include, modules, but not all modules are packages. As such,
import would only be used for installed packages and not for my own modules.
But the documentation for import routinely makes reference to modules, leading
myself to incorrectly believe that I could import my own local modules using
import.
I?ve been reading through the page regarding scope that Brent referenced and
feel as though it has clarified a few things, but also raised many more
questions. Unfortunately it doesn?t make a clear distinction between packages
and modules either.
>From
>http://www.haskell.org/ghc/docs/7.6.3/html/users_guide/interactive-evaluation.html#ghci-scope
2.4.5.1. :module and :load
I?d love to get a clear definition of ?loaded" vs "in scope". Does import only
bring a module into scope, not load it? Then would installed packages be
considered loaded but not in scope? But they don?t show up with :show modules.
Would using import then place them in scope? My personal modules would be
neither loaded, nor in scope? Using :load loads them and also places them in
scope? Using :modules -m would remove a module from scope but it would still
be loaded?
Lots and lots of questions. If anyone has any links to documentation that
would clear up some of these questions, I?d appreciate it. Anyway, it appears
that using import is not possible for my modules, only for installed packages,
so using :load and :add are the correct solution.
Thanks again for the help,
James
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 69, Issue 12
*****************************************