# Beginners Digest, Vol 99, Issue 12

```Send Beginners mailing list submissions to

To subscribe or unsubscribe via the World Wide Web, visit
or, via email, send a message with subject or body 'help' to
```
You can reach the person managing the list at

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
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:

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

Message: 2
Date: Thu, 22 Sep 2016 12:33:11 +0200
Subject: Re: [Haskell-beginners] is this right?
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

-------------- next part --------------
An HTML attachment was scrubbed...
URL:

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

Subject: Digest Footer

_______________________________________________
Beginners mailing list