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. Re: how to skip pattern match error when applying a mapM_ (Daniel Trstenjak) 2. Re: how to skip pattern match error when applying a mapM_ (jean verdier) 3. Re: how to skip pattern match error when applying a mapM_ (Daniel Trstenjak) 4. Re: how to skip pattern match error when applying a mapM_ (PICCA Frederic-Emmanuel) 5. Re: how to skip pattern match error when applying a mapM_ (Daniel Trstenjak) 6. Re: how to skip pattern match error when applying a mapM_ (PICCA Frederic-Emmanuel) 7. Re: how to skip pattern match error when applying a mapM_ (Daniel Trstenjak) ---------------------------------------------------------------------- Message: 1 Date: Tue, 17 Jan 2017 19:06:11 +0100 From: Daniel Trstenjak <daniel.trsten...@gmail.com> To: beginners@haskell.org Subject: Re: [Haskell-beginners] how to skip pattern match error when applying a mapM_ Message-ID: <20170117180611.GA16815@octa> Content-Type: text/plain; charset=us-ascii Hi Frederic, On Tue, Jan 17, 2017 at 05:34:05PM +0000, PICCA Frederic-Emmanuel wrote: > I tought that was the purpose of the Monad to avoid writting these > boillerplate ? > > What I am missing ? You don't pattern match on 'Just' but just write: gamma <- get_position' (h5gamma d) 0 delta <- get_position' (h5delta d) idx wavelength <- get_position' (h5wavelength d) 0 If e.g. 'gamma' is 'Nothing', then the following expressions aren't evaluated and the whole "do-block" returns 'Nothing'. Greetings, Daniel ------------------------------ Message: 2 Date: Tue, 17 Jan 2017 19:17:10 +0100 From: jean verdier <verdier.j...@gmail.com> To: beginners@haskell.org Subject: Re: [Haskell-beginners] how to skip pattern match error when applying a mapM_ Message-ID: <1484677030.3065.8.ca...@gmail.com> Content-Type: text/plain; charset="UTF-8" Just x <- y is a construction similar to let Just x = y which is the same as x = case y of Just z -> z Nothing -> error "pattern match failed" Some matches are mapped to errors but not explicitly. Just x = y avoid some boilerplate at the cost of hiding the non exhaustive matches that may raise unexpected errors. Just x <- y is the same as z <- y let x = case z of ... On Tue, 2017-01-17 at 17:34 +0000, PICCA Frederic-Emmanuel wrote: > > > > Just gamma <- get_position' (h5gamma d) 0 > > Just delta <- get_position' (h5delta d) idx > > Just wavelength <- get_position' (h5wavelength d) 0 > > > > > is asking for a trouble down the road. Use a case to pattern match > > on nothing, (or `maybe`, or LambdaCase if you are into extensions). > > I tought that was the purpose of the Monad to avoid writting these > boillerplate ? > > What I am missing ? > > Cheers > > Frederic > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ Message: 3 Date: Tue, 17 Jan 2017 19:21:38 +0100 From: Daniel Trstenjak <daniel.trsten...@gmail.com> To: beginners@haskell.org Subject: Re: [Haskell-beginners] how to skip pattern match error when applying a mapM_ Message-ID: <20170117182138.GB16815@octa> Content-Type: text/plain; charset=us-ascii > If e.g. 'gamma' is 'Nothing', then the following expressions aren't evaluated > and the whole "do-block" returns 'Nothing'. I just saw that 'row' isn't operating in the 'Maybe' monad but in the 'IO' monad, so this wont work. I don't know if 'row' contains any side effects that should also be executed if the returned 'Maybe' is 'Nothing', if this isn't the case, then you might be able to switch the return type of 'row' from 'IO (Maybe ...)' to 'Maybe (IO ...)' and then you could get the described behaviour for 'Maybe'. Greetings, Daniel ------------------------------ Message: 4 Date: Tue, 17 Jan 2017 19:44:31 +0000 From: PICCA Frederic-Emmanuel <frederic-emmanuel.pi...@synchrotron-soleil.fr> To: "The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell" <beginners@haskell.org> Subject: Re: [Haskell-beginners] how to skip pattern match error when applying a mapM_ Message-ID: <a2a20ec3b8560d408356cac2fc148e53bb329...@sun-dag3.synchrotron-soleil.fr> Content-Type: text/plain; charset="us-ascii" > I don't know if 'row' contains any side effects that should also be > executed if the returned 'Maybe' is 'Nothing', if this isn't the case, > then you might be able to switch the return type of 'row' from > 'IO (Maybe ...)' to 'Maybe (IO ...)' and then you could get the > described behaviour for 'Maybe'. As soon as one side effect return Nothing, it should stop the IO monad. so I should definitiely switch to Maybe IO now how can I know the behaviour in between the line of a Monad. I aimagine that this is the purpose of the bind method (>>=). Where is this defined for Maybe and IO ? Thanks Frederic ------------------------------ Message: 5 Date: Tue, 17 Jan 2017 21:36:37 +0100 From: Daniel Trstenjak <daniel.trsten...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] how to skip pattern match error when applying a mapM_ Message-ID: <53a63195-75d3-4b94-87dd-3c7ef094a...@gmail.com> Content-Type: text/plain; charset="utf-8" > now how can I know the behaviour in between the line of a Monad. > I aimagine that this is the purpose of the bind method (>>=). Yes, that's the case. > Where is this defined for Maybe and IO ? You just look at the Monad instance for the type. IO is a bit special, but here is the one for Maybe[1]. Greetings, Daniel [1] http://hackage.haskell.org/package/base-4.9.1.0/docs/src/GHC.Base.html#line-665 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20170117/804cf018/attachment-0001.html> ------------------------------ Message: 6 Date: Tue, 17 Jan 2017 20:46:32 +0000 From: PICCA Frederic-Emmanuel <frederic-emmanuel.pi...@synchrotron-soleil.fr> To: "The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell" <beginners@haskell.org> Subject: Re: [Haskell-beginners] how to skip pattern match error when applying a mapM_ Message-ID: <a2a20ec3b8560d408356cac2fc148e53bb329...@sun-dag3.synchrotron-soleil.fr> Content-Type: text/plain; charset="us-ascii" > You just look at the Monad instance for the type. IO is a bit special, but > here is the one for Maybe[1]. thanks and what is the purpose of fail _ = nothing Cheers Fred ------------------------------ Message: 7 Date: Tue, 17 Jan 2017 22:28:47 +0100 From: Daniel Trstenjak <daniel.trsten...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] how to skip pattern match error when applying a mapM_ Message-ID: <e4ceb443-7340-421e-84bf-89e8a8b42...@gmail.com> Content-Type: text/plain; charset=utf-8 > thanks and what is the purpose of > > fail _ = nothing ’fail’ is called for pattern match errors, pretty much the error you’ve got from ’Just x <- ...’. The IO Monad instance raises the exception you've seen. For the Maybe Monad instance just 'Nothing' is returned. Greetings, Daniel ------------------------------ Subject: Digest Footer _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ End of Beginners Digest, Vol 103, Issue 15 ******************************************