Send Beginners mailing list submissions to
        beginners@haskell.org

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
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Ignoring the result of a monadic computation
      (Magnus Therning)
   2. Re:  Ignoring the result of a monadic computation (Brent Yorgey)
   3. Re:  Ignoring the result of a monadic computation
      (Magnus Therning)


----------------------------------------------------------------------

Message: 1
Date: Fri, 19 Nov 2010 15:26:04 +0000
From: Magnus Therning <mag...@therning.org>
Subject: Re: [Haskell-beginners] Ignoring the result of a monadic
        computation
To: beginners <beginners@haskell.org>
Message-ID:
        <aanlkti=pgoo0qccntfcw35dwgxgoqu12kcpmsbj3y...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

On Fri, Nov 19, 2010 at 15:21, Brent Yorgey <byor...@seas.upenn.edu> wrote:
> On Fri, Nov 19, 2010 at 07:56:02AM +0100, Tim Baumgartner wrote:
>> Hi,
>>
>> while learning about monads, I had something like
>>
>> do
>>    line <- getLine
>>    something
>>    putStrLn line
>>
>> and I wondered if I could write it in one line, without naming of parameters.
>> I finally came up with
>>
>> getLine >>= ignore something >>= putStrLn
>>
>> using
>> ignore :: Monad m => m a -> b -> m b
>> ignore m a = m >> return a
>>
>> I'm satisfied with this solution but searching hoogle I didn't find
>> a standard function for my ignore. Am I missing something?
>
> Nope, there isn't such a function, but I like it.  It reminds me of
> (*>) and (<*) from Control.Applicative.  Note that you sometimes see
> the name 'ignore' used for a slightly different function, namely
>
>  ignore :: Monad m => m a -> m ()
>  ignore m = m >> return ()
>
> but yours is a bit more general.  Other names for your function might
> be 'passThrough' or something like that.

I'm not sure I see any benefit of ': m a -> b -> m b' over 'm a -> m
()'.  When would you want to use the former?

/M

-- 
Magnus Therning                        (OpenPGP: 0xAB4DFBA4)
magnus@therning.org          Jabber: magnus@therning.org
http://therning.org/magnus         identi.ca|twitter: magthe


------------------------------

Message: 2
Date: Fri, 19 Nov 2010 10:31:01 -0500
From: Brent Yorgey <byor...@seas.upenn.edu>
Subject: Re: [Haskell-beginners] Ignoring the result of a monadic
        computation
To: beginners@haskell.org
Message-ID: <20101119153101.ga30...@seas.upenn.edu>
Content-Type: text/plain; charset=iso-8859-1

On Fri, Nov 19, 2010 at 03:26:04PM +0000, Magnus Therning wrote:
> On Fri, Nov 19, 2010 at 15:21, Brent Yorgey <byor...@seas.upenn.edu> wrote:
> > On Fri, Nov 19, 2010 at 07:56:02AM +0100, Tim Baumgartner wrote:
> >> Hi,
> >>
> >> while learning about monads, I had something like
> >>
> >> do
> >>    line <- getLine
> >>    something
> >>    putStrLn line
> >>
> >> and I wondered if I could write it in one line, without naming of 
> >> parameters.
> >> I finally came up with
> >>
> >> getLine >>= ignore something >>= putStrLn
> >>
> >> using
> >> ignore :: Monad m => m a -> b -> m b
> >> ignore m a = m >> return a
> >>
> >> I'm satisfied with this solution but searching hoogle I didn't find
> >> a standard function for my ignore. Am I missing something?
> >
> > Nope, there isn't such a function, but I like it.  It reminds me of
> > (*>) and (<*) from Control.Applicative.  Note that you sometimes see
> > the name 'ignore' used for a slightly different function, namely
> >
> >  ignore :: Monad m => m a -> m ()
> >  ignore m = m >> return ()
> >
> > but yours is a bit more general.  Other names for your function might
> > be 'passThrough' or something like that.
> 
> I'm not sure I see any benefit of ': m a -> b -> m b' over 'm a -> m
> ()'.  When would you want to use the former?

>From the OP's message:

  getLine >>= ignore something >>= putStrLn

which executes 'something' for its side effect and passes the result
of getLine through to putStrLn, without ever having to give a name to
the result of getLine.  IIUC this was the whole point.

-Brent


------------------------------

Message: 3
Date: Fri, 19 Nov 2010 15:37:10 +0000
From: Magnus Therning <mag...@therning.org>
Subject: Re: [Haskell-beginners] Ignoring the result of a monadic
        computation
To: Brent Yorgey <byor...@seas.upenn.edu>
Cc: beginners@haskell.org
Message-ID:
        <aanlktimbor4ilunr3mtvews4plpatj2fpgc_mpbsp...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

On Fri, Nov 19, 2010 at 15:31, Brent Yorgey <byor...@seas.upenn.edu> wrote:
> On Fri, Nov 19, 2010 at 03:26:04PM +0000, Magnus Therning wrote:
>> On Fri, Nov 19, 2010 at 15:21, Brent Yorgey <byor...@seas.upenn.edu> wrote:
>> > On Fri, Nov 19, 2010 at 07:56:02AM +0100, Tim Baumgartner wrote:
>> >> Hi,
>> >>
>> >> while learning about monads, I had something like
>> >>
>> >> do
>> >>    line <- getLine
>> >>    something
>> >>    putStrLn line
>> >>
>> >> and I wondered if I could write it in one line, without naming of 
>> >> parameters.
>> >> I finally came up with
>> >>
>> >> getLine >>= ignore something >>= putStrLn
>> >>
>> >> using
>> >> ignore :: Monad m => m a -> b -> m b
>> >> ignore m a = m >> return a
>> >>
>> >> I'm satisfied with this solution but searching hoogle I didn't find
>> >> a standard function for my ignore. Am I missing something?
>> >
>> > Nope, there isn't such a function, but I like it.  It reminds me of
>> > (*>) and (<*) from Control.Applicative.  Note that you sometimes see
>> > the name 'ignore' used for a slightly different function, namely
>> >
>> >  ignore :: Monad m => m a -> m ()
>> >  ignore m = m >> return ()
>> >
>> > but yours is a bit more general.  Other names for your function might
>> > be 'passThrough' or something like that.
>>
>> I'm not sure I see any benefit of ': m a -> b -> m b' over 'm a -> m
>> ()'.  When would you want to use the former?
>
> >From the OP's message:
>
>  getLine >>= ignore something >>= putStrLn
>
> which executes 'something' for its side effect and passes the result
> of getLine through to putStrLn, without ever having to give a name to
> the result of getLine.  IIUC this was the whole point.

IMNSHO, not such a strong argument for such a function though. :-)

/M

-- 
Magnus Therning                        (OpenPGP: 0xAB4DFBA4)
magnus@therning.org          Jabber: magnus@therning.org
http://therning.org/magnus         identi.ca|twitter: magthe


------------------------------

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 29, Issue 28
*****************************************

Reply via email to