
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

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
participants (2)
-
Dennis Raddle
-
Sylvain Henry