Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/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: I have a -> f a. How to get m a -> f m a ? (Baa)
2. get rid of IO in [IO XXX] ([email protected])
3. Re: get rid of IO in [IO XXX] (Mihai Maruseac)
4. Re: get rid of IO in [IO XXX] (Alex Belanger)
5. Re: Beginners Digest, Vol 111, Issue 4 (Jack Brandt)
----------------------------------------------------------------------
Message: 1
Date: Mon, 4 Sep 2017 15:36:42 +0300
From: Baa <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] I have a -> f a. How to get m a -> f
m a ?
Message-ID: <20170904153642.7e839b91@Pavel>
Content-Type: text/plain; charset=US-ASCII
Hello, Imants! Exactly :)
Thanks!
> > I have function a -> IO a. How to get function:
> > Maybe a -> IO (Maybe a) ?
>
> Will mapM work:
>
> http://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Traversable.html#v:mapM
>
> ?
>
>
>
> On 4 September 2017 at 15:06, Baa <[email protected]> wrote:
>
> > Hello List!
> >
> > I have function a -> IO a. How to get function:
> >
> > Maybe a -> IO (Maybe a) ?
> >
> > I found in Haskell mails archive such thing:
> >
> > class IFunctor f where
> > imap :: Idiom i => (s -> i t) -> f s -> i (f t)
> >
> > which looks similar, but I didn't find any helpfull instances of
> > `IFunctor` class in its package (and unfortunately I don't know
> > what are the indexed types: IMonad, IFunctor, etc). Sure, there is
> > the primitive solution like:
> >
> > myfunc :: a -> IO a
> > ...
> > f x = case x of Nothing -> return Nothing
> > Just x' -> Just <$> myfunc x'
> >
> > but more interesting is to know more standard and Haskelish solution
> > (like lift's, etc). May be I miss something very obvious..
> >
> > ===
> > Best regards, Paul
> > _______________________________________________
> > Beginners mailing list
> > [email protected]
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> >
------------------------------
Message: 2
Date: Mon, 4 Sep 2017 18:04:42 +0200 (CEST)
From: [email protected]
To: [email protected]
Subject: [Haskell-beginners] get rid of IO in [IO XXX]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8
What is the way to transform a list of [IO XXX] type to [XXX]?
Thanks,
Alexei
------------------------------
Message: 3
Date: Mon, 4 Sep 2017 09:09:07 -0700
From: Mihai Maruseac <[email protected]>
To: [email protected], The Haskell-Beginners Mailing List - Discussion
of primarily beginner-level topics related to Haskell
<[email protected]>
Subject: Re: [Haskell-beginners] get rid of IO in [IO XXX]
Message-ID:
<caomsumkussdw5+svj2kdczvr9bdwqpwakfwwpe6mro3oefb...@mail.gmail.com>
Content-Type: text/plain; charset="UTF-8"
Hi,
Use sequence. It has type t (m a) -> m (t a) where m is a Monad (like
IO) and t is a Traversable (like the list).
Documentation:
http://hackage.haskell.org/package/base-4.10.0.0/docs/Prelude.html#v:sequence
I got to it using Hoogle:
https://www.haskell.org/hoogle/?hoogle=%5BIO+a%5D+-%3E+IO+%5Ba%5D
On Mon, Sep 4, 2017 at 9:04 AM, <[email protected]> wrote:
> What is the way to transform a list of [IO XXX] type to [XXX]?
>
> Thanks,
> Alexei
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
--
Mihai Maruseac (MM)
"If you can't solve a problem, then there's an easier problem you can
solve: find it." -- George Polya
------------------------------
Message: 4
Date: Mon, 4 Sep 2017 12:38:25 -0400
From: Alex Belanger <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>,
[email protected]
Subject: Re: [Haskell-beginners] get rid of IO in [IO XXX]
Message-ID:
<cadsky2z-uq+poysbtaz0yspe8aomcyzbmawdhwv5bs-q5ud...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
You can turn `[IO a]` into `IO [a]` by traversing the Traversable and
sequencing the actions using `sequence`.
Note that what it creates is a slightly different IO computation that
re-organizes the results, you'll still need to run that IO in the end.
Typically, it's passed all the way down to your closest use of IO (often
main for beginners) where you'll be able to finally get rid of it by
performing the effects and doing something with the results. The flavor of
choice depends on the situation but I find the IO monad very readable.
main :: IO ()
main = do
listOfA <- sequence ioListOfA
-- Use listOfA from here
Alex
On Sep 4, 2017 12:05 PM, <[email protected]> wrote:
> What is the way to transform a list of [IO XXX] type to [XXX]?
>
> Thanks,
> Alexei
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20170904/9001616c/attachment-0001.html>
------------------------------
Message: 5
Date: Mon, 4 Sep 2017 12:33:30 -0500
From: Jack Brandt <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Beginners Digest, Vol 111, Issue 4
Message-ID:
<CAL6jW6NapihhO25dFNBMXuc4O6waMxbNnM7cOLRe3Bq9U0=y...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Would a specialization of return work, as in
f = return :: Maybe a -> IO (Maybe a)?
On Mon, Sep 4, 2017 at 7:00 AM, <[email protected]> wrote:
> Send Beginners mailing list submissions to
> [email protected]
>
> To subscribe or unsubscribe via the World Wide Web, visit
> http://mail.haskell.org/cgi-bin/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. I have a -> f a. How to get m a -> f m a ? (Baa)
> 2. Re: I have a -> f a. How to get m a -> f m a ? (Imants Cekusins)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Mon, 4 Sep 2017 15:06:34 +0300
> From: Baa <[email protected]>
> To: [email protected]
> Subject: [Haskell-beginners] I have a -> f a. How to get m a -> f m a
> ?
> Message-ID: <20170904150634.230dd5ff@Pavel>
> Content-Type: text/plain; charset=US-ASCII
>
> Hello List!
>
> I have function a -> IO a. How to get function:
>
> Maybe a -> IO (Maybe a) ?
>
> I found in Haskell mails archive such thing:
>
> class IFunctor f where
> imap :: Idiom i => (s -> i t) -> f s -> i (f t)
>
> which looks similar, but I didn't find any helpfull instances of
> `IFunctor` class in its package (and unfortunately I don't know what are
> the indexed types: IMonad, IFunctor, etc). Sure, there is the primitive
> solution like:
>
> myfunc :: a -> IO a
> ...
> f x = case x of Nothing -> return Nothing
> Just x' -> Just <$> myfunc x'
>
> but more interesting is to know more standard and Haskelish solution
> (like lift's, etc). May be I miss something very obvious..
>
> ===
> Best regards, Paul
>
>
> ------------------------------
>
> Message: 2
> Date: Mon, 4 Sep 2017 15:14:42 +0300
> From: Imants Cekusins <[email protected]>
> To: The Haskell-Beginners Mailing List - Discussion of primarily
> beginner-level topics related to Haskell <[email protected]>
> Subject: Re: [Haskell-beginners] I have a -> f a. How to get m a -> f
> m a ?
> Message-ID:
> <CAP1qinaEhE6HqvS0O9-CfV9Vc2x8ZvfQ_SRFXQgVH-
> [email protected]>
> Content-Type: text/plain; charset="utf-8"
>
> > I have function a -> IO a. How to get function:
> > Maybe a -> IO (Maybe a) ?
>
> Will mapM work:
>
> http://hackage.haskell.org/package/base-4.10.0.0/docs/
> Data-Traversable.html#v:mapM
>
> ?
>
>
>
> On 4 September 2017 at 15:06, Baa <[email protected]> wrote:
>
> > Hello List!
> >
> > I have function a -> IO a. How to get function:
> >
> > Maybe a -> IO (Maybe a) ?
> >
> > I found in Haskell mails archive such thing:
> >
> > class IFunctor f where
> > imap :: Idiom i => (s -> i t) -> f s -> i (f t)
> >
> > which looks similar, but I didn't find any helpfull instances of
> > `IFunctor` class in its package (and unfortunately I don't know what are
> > the indexed types: IMonad, IFunctor, etc). Sure, there is the primitive
> > solution like:
> >
> > myfunc :: a -> IO a
> > ...
> > f x = case x of Nothing -> return Nothing
> > Just x' -> Just <$> myfunc x'
> >
> > but more interesting is to know more standard and Haskelish solution
> > (like lift's, etc). May be I miss something very obvious..
> >
> > ===
> > Best regards, Paul
> > _______________________________________________
> > Beginners mailing list
> > [email protected]
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> >
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://mail.haskell.org/pipermail/beginners/
> attachments/20170904/f82f05da/attachment-0001.html>
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
> ------------------------------
>
> End of Beginners Digest, Vol 111, Issue 4
> *****************************************
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20170904/9b4c0ee6/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 111, Issue 5
*****************************************