Send Beginners mailing list submissions to
        beginners@haskell.org

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
        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.  is this right? (Dennis Raddle)
   2. Re:  is this right? (Sylvain Henry)


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

Message: 1
Date: Thu, 22 Sep 2016 02:57:17 -0700
From: Dennis Raddle <dennis.rad...@gmail.com>
To: Haskell Beginners <beginners@haskell.org>
Subject: [Haskell-beginners] is this right?
Message-ID:
        <CAKxLvoo4AuA=3Y9FVBW6qMmJm3N8KshE7krX=n6wwpq+++p...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

I want to evaluate a function on a series of inputs:

f :: a -> Maybe b

then collect the results [b] if they are all Just, or terminate the
computation immediately upon hitting Nothing.

This is exactly what mapM does in the Maybe monad, correct?

In particular I want to make sure that it will not try to evaluate anything
past the first 'Nothing' result as the efficiency of my design is based on
that.

D
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20160922/3d0dfb99/attachment-0001.html>

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

Message: 2
Date: Thu, 22 Sep 2016 12:33:11 +0200
From: Sylvain Henry <sylv...@haskus.fr>
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] is this right?
Message-ID: <44e48242-044f-6d01-4488-8e06cdc54...@haskus.fr>
Content-Type: text/plain; charset="utf-8"; Format="flowed"

Hi,

Yes it's correct. You can check this with ghci:

f :: Integer -> Maybe Integer
f 5 = Nothing
f x = Just x

 > let xs = [1..] :: [Integer]
 > mapM f xs
Nothing  (it doesn't loop forever)
 > :sprint xs
xs = 1 : 2 : 3 : 4 : 5 : _   (the tail after 5 is not evaluated)

Cheers
Sylvain

On 22/09/2016 11:57, Dennis Raddle wrote:
> I want to evaluate a function on a series of inputs:
>
> f :: a -> Maybe b
>
> then collect the results [b] if they are all Just, or terminate the 
> computation immediately upon hitting Nothing.
>
> This is exactly what mapM does in the Maybe monad, correct?
>
> In particular I want to make sure that it will not try to evaluate 
> anything past the first 'Nothing' result as the efficiency of my 
> design is based on that.
>
> D
>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20160922/bd17a99a/attachment-0001.html>

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

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


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

End of Beginners Digest, Vol 99, Issue 12
*****************************************

Reply via email to