
Hi, dons mentions in his blog post that Data.Map’s lookup is generalized over the Monads, whereas Prelude.maybe isn’t. Are there good reasons not to do that to Prelude.maybe as well? Alternatively, how about adding this function to Data.Maybe, analogous to maybeToList
maybeToM Nothing = fail "Nothing" maybeToM (Just x) = return x
(Incidentially, this function is the same as maybeToList if run in the List Monad). This way, Prelude.lookup (or any function that returns a Maybe) can be generalized as (maybeToM . lookup). Greetings, Joachim -- Joachim "nomeata" Breitner mail: mail@joachim-breitner.de | ICQ# 74513189 | GPG-Key: 4743206C JID: joachimbreitner@amessage.de | http://www.joachim-breitner.de/ Debian Developer: nomeata@debian.org

On Mon, Dec 18, 2006 at 09:29:24AM +0000, Joachim Breitner wrote:
dons mentions in his blog post that Data.Map???s lookup is generalized over the Monads, whereas Prelude.maybe isn???t. Are there good reasons not to do that to Prelude.maybe as well?
I can't see how such a generalization could look like, especially since "maybe" can be used with arbitrary monad: maybe (fail "Nothing") return Best regards Tomasz

Hi, Am Montag, den 18.12.2006, 17:42 +0100 schrieb Tomasz Zielonka:
On Mon, Dec 18, 2006 at 09:29:24AM +0000, Joachim Breitner wrote:
dons mentions in his blog post that Data.Map???s lookup is generalized over the Monads, whereas Prelude.maybe isn???t. Are there good reasons not to do that to Prelude.maybe as well?
I can't see how such a generalization could look like, especially since "maybe" can be used with arbitrary monad: maybe (fail "Nothing") return
Well, that’s a possible implementation of a maybeToM. The question is: Is it useful enough for a name on it’s own? Greetings, Joachim -- Joachim "nomeata" Breitner mail: mail@joachim-breitner.de | ICQ# 74513189 | GPG-Key: 4743206C JID: joachimbreitner@amessage.de | http://www.joachim-breitner.de/ Debian Developer: nomeata@debian.org

On Mon, Dec 18, 2006 at 04:59:45PM +0000, Joachim Breitner wrote:
Well, that???s a possible implementation of a maybeToM. The question is: Is it useful enough for a name on it???s own?
...and for putting it in Prelude? It would be interesting to try to estimate the number of functions useful enough for putting in Prelude - I am starting to be afraid that there will be too many of them. One of the nice things about functional languages is that you can create such functions by combining higher-order functions, without the need to name the resulting function. Maybe we could agree to put in Prelude only the N (200? 1000?) most useful functions ;-) I am not sure about maybeToM - maybe it will be found useful to many. Best regards Tomasz

Hi, Am Montag, den 18.12.2006, 18:12 +0100 schrieb Tomasz Zielonka:
On Mon, Dec 18, 2006 at 04:59:45PM +0000, Joachim Breitner wrote:
Well, that???s a possible implementation of a maybeToM. The question is: Is it useful enough for a name on it???s own?
...and for putting it in Prelude?
Actually, I’d not put it in Prelude, just Data.Maybe, along the other Maybe related functions.
It would be interesting to try to estimate the number of functions useful enough for putting in Prelude - I am starting to be afraid that there will be too many of them.
One of the nice things about functional languages is that you can create such functions by combining higher-order functions, without the need to name the resulting function.
Well, maybeToM could be a glue function that, if it appears in the code at all, probably appears a lot of time, so it will have to be named. And if it has to be named, you can name it once for all. Another point is that the presence of the function alone might inspire people to use it in ways that they would not even think of. Until a very recent post here or on planet I would not have thought of using pattern matching failures deliberately to fail one part of a List computation. So giving such a function a name advocates a certain use. Greetings, Joachim -- Joachim Breitner e-Mail: mail@joachim-breitner.de Homepage: http://www.joachim-breitner.de ICQ#: 74513189

I can't see how such a generalization could look like, especially since "maybe" can be used with arbitrary monad: maybe (fail "Nothing") return
Well, that???s a possible implementation of a maybeToM. The question is: Is it useful enough for a name on it???s own?
I thought it was useful enough in genericserialize: module Data.Generics.Serialization.Standard ... -- |Convert a 'Maybe' object into any monad, using the imbedding defined by -- fail and return. fromMaybeM :: Monad m => String -> Maybe a -> m a fromMaybeM st = maybe (fail st) return

Hi, Am Montag, den 18.12.2006, 09:22 -0800 schrieb Stefan O'Rear:
module Data.Generics.Serialization.Standard ...
-- |Convert a 'Maybe' object into any monad, using the imbedding defined by -- fail and return. fromMaybeM :: Monad m => String -> Maybe a -> m a fromMaybeM st = maybe (fail st) return
I can’t find that module anywhere (with neither [gh]oogle). But I guess that is another indicator that it’s useful to use Maybe in other Monads. Greetings, Joachim -- Joachim "nomeata" Breitner mail: mail@joachim-breitner.de | ICQ# 74513189 | GPG-Key: 4743206C JID: joachimbreitner@amessage.de | http://www.joachim-breitner.de/ Debian Developer: nomeata@debian.org

On 18 dec 2006, at 18.22, Stefan O'Rear wrote:
I can't see how such a generalization could look like, especially since "maybe" can be used with arbitrary monad: maybe (fail "Nothing") return
Well, that???s a possible implementation of a maybeToM. The question is: Is it useful enough for a name on it???s own?
I thought it was useful enough in genericserialize:
module Data.Generics.Serialization.Standard ...
-- |Convert a 'Maybe' object into any monad, using the imbedding defined by -- fail and return. fromMaybeM :: Monad m => String -> Maybe a -> m a fromMaybeM st = maybe (fail st) return
I agree that this is useful. Several of my applications and libraries include this somewhere (with different names: maybeM and maybeToM). Though the RHS isn't much shorter than the LHS, unless its name is made shorter. /Björn

On Mon, Dec 18, 2006 at 04:59:45PM +0000, Joachim Breitner wrote:
Well, that???s a possible implementation of a maybeToM. The question is: Is it useful enough for a name on it???s own?
OK, I agree it's sufficiently useful, and it's a generalization of Data.Maybe.maybeToList. Perhaps we could get rid of maybeToList? Best regards Tomasz
participants (4)
-
Bjorn Bringert
-
Joachim Breitner
-
Stefan O'Rear
-
Tomasz Zielonka