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. Combining IO and Either function to "EitherT e IO a"
(Nathan H?sken)
2. Re: Combining IO and Either function to "EitherT e IO a"
(Mateusz Kowalczyk)
3. Re: Combining IO and Either function to "EitherT e IO a"
(Mateusz Kowalczyk)
4. Re: Combining IO and Either function to "EitherT e IO a"
(Kim-Ee Yeoh)
5. Re: Combining IO and Either function to "EitherT e IO a"
(Nathan H?sken)
6. Using GHCi, import submodule that needs to import another
submodule? (James Toll)
7. Re: Using GHCi, import submodule that needs to import
another submodule? (Daniel Trstenjak)
----------------------------------------------------------------------
Message: 1
Date: Wed, 05 Mar 2014 14:53:22 +0100
From: Nathan H?sken <[email protected]>
To: Haskell Beginners Mailinglist <[email protected]>
Subject: [Haskell-beginners] Combining IO and Either function to
"EitherT e IO a"
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Hey,
I have a function
|func1 :: IO String
|
and another:
|func2 :: String -> Either String String
|
and I want to combine them, giving the output of the first as the input
as the second.
|func3 :: IO (Either String String)
func3 = do
tmp <- func1
return (func2 tmp)
|
Ok, possible. But I rather would like a result of type "EitherT String
IO String".
So how can I combine these function in a smart way, to get the needed
result?
Thanks!
Nathan
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20140305/3626d577/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: OpenPGP digital signature
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20140305/3626d577/attachment-0001.sig>
------------------------------
Message: 2
Date: Wed, 05 Mar 2014 14:31:59 +0000
From: Mateusz Kowalczyk <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Combining IO and Either function to
"EitherT e IO a"
Message-ID: <[email protected]>
Content-Type: text/plain; charset=windows-1252
On 05/03/14 13:53, Nathan H?sken wrote:
> Hey,
>
> I have a function
>
> |func1 :: IO String
> |
>
> and another:
>
> |func2 :: String -> Either String String
> |
>
> and I want to combine them, giving the output of the first as the input
> as the second.
>
> |func3 :: IO (Either String String)
> func3 = do
> tmp <- func1
> return (func2 tmp)
> |
>
This is just ?fmap func2 func1? or using the operator, ?func2 <$> func1?.
> Ok, possible. But I rather would like a result of type "EitherT String
> IO String".
> So how can I combine these function in a smart way, to get the needed
> result?
After using ?func2 <$> func1? we have ?IO (Either String String)? as you
point out. The ?EitherT? constructor has type ?m (Either e a)?. Here if
m = IO, e = String, a = String so we have exactly what we need:
> > :t EitherT $ func2 <$> func1
> EitherT $ func2 <$> func1 :: EitherT String IO String
>
> Thanks!
> Nathan
>
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
--
Mateusz K.
------------------------------
Message: 3
Date: Wed, 05 Mar 2014 14:33:17 +0000
From: Mateusz Kowalczyk <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Combining IO and Either function to
"EitherT e IO a"
Message-ID: <[email protected]>
Content-Type: text/plain; charset=windows-1252
On 05/03/14 14:31, Mateusz Kowalczyk wrote:
> On 05/03/14 13:53, Nathan H?sken wrote:
>> Hey,
>>
>> I have a function
>>
>> |func1 :: IO String
>> |
>>
>> and another:
>>
>> |func2 :: String -> Either String String
>> |
>>
>> and I want to combine them, giving the output of the first as the input
>> as the second.
>>
>> |func3 :: IO (Either String String)
>> func3 = do
>> tmp <- func1
>> return (func2 tmp)
>> |
>>
>
> This is just ?fmap func2 func1? or using the operator, ?func2 <$> func1?.
>
>> Ok, possible. But I rather would like a result of type "EitherT String
>> IO String".
>> So how can I combine these function in a smart way, to get the needed
>> result?
>
> After using ?func2 <$> func1? we have ?IO (Either String String)? as you
> point out. The ?EitherT? constructor has type ?m (Either e a)?.
Oops, that meant to say that it takes a sole argument of that type.
> Here if
> m = IO, e = String, a = String so we have exactly what we need:
>
>>> :t EitherT $ func2 <$> func1
>> EitherT $ func2 <$> func1 :: EitherT String IO String
>
>>
>> Thanks!
>> Nathan
>>
>>
>>
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>
>
--
Mateusz K.
------------------------------
Message: 4
Date: Wed, 5 Mar 2014 23:45:43 +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+zdqbcurvw-o+ccj4cjxhyxelfb4mgn5iosmqvuhdctz...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
On Wed, Mar 5, 2014 at 8:53 PM, Nathan H?sken <[email protected]>wrote:
> I have a function
>
> func1 :: IO String
>
>
How is func1 a function?
-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20140305/046f4a9e/attachment-0001.html>
------------------------------
Message: 5
Date: Wed, 05 Mar 2014 18:49:32 +0100
From: Nathan H?sken <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Combining IO and Either function to
"EitherT e IO a"
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Mmh, I might not have used haskell terminology correctly. Its a
function, in the sense of a function of an imperative language ...
Anyhow, the tip from Mateusz worked helped me a lot, thanks for that!
On 03/05/2014 05:45 PM, Kim-Ee Yeoh wrote:
>
> On Wed, Mar 5, 2014 at 8:53 PM, Nathan H?sken
> <[email protected] <mailto:[email protected]>> wrote:
>
> I have a function
>
> |func1 :: IO String|
>
>
> How is func1 a function?
>
> -- Kim-Ee
>
>
> _______________________________________________
> 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/3e914c75/attachment-0001.html>
------------------------------
Message: 6
Date: Wed, 5 Mar 2014 12:07:33 -0600
From: James Toll <[email protected]>
To: haskell-beginners <[email protected]>
Subject: [Haskell-beginners] Using GHCi, import submodule that needs
to import another submodule?
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
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
------------------------------
Message: 7
Date: Wed, 5 Mar 2014 19:17:05 +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: <20140305181705.GA19433@machine>
Content-Type: text/plain; charset=us-ascii
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
Greetings,
Daniel
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 69, Issue 11
*****************************************