28 May 12:11
Re: #2309: containers: specialize functions that fail in a Monad to Maybe
From: Conor McBride <conor <at> strictlypositive.org>
Subject: Re: #2309: containers: specialize functions that fail in a Monad to Maybe
Newsgroups: gmane.comp.lang.haskell.libraries
Date: 2008-05-28 10:11:32 GMT
Subject: Re: #2309: containers: specialize functions that fail in a Monad to Maybe
Newsgroups: gmane.comp.lang.haskell.libraries
Date: 2008-05-28 10:11:32 GMT
Hi On 28 May 2008, at 10:21, apfelmus wrote: > Ross Paterson wrote: >> Several functions on containers used to have types like >> lookup :: (Ord k) => k -> Map k a -> Maybe a >> but these were generalized to >> lookup :: (Monad m, Ord k) => k -> Map k a -> m a >> The proposal is to change these signatures back, specializing them >> to Maybe. > > I'm all for Maybe in the question Monad VS Maybe. Me too. (+1) for Ross's proposal. [..] > Also, it's not entirely clear whether MonadZero is the most general > abstraction. Is ApplicativeZero better? Or something else? Maybe is the most general abstraction. Requiring (>>=), or even (<*>) seems excessive. What we need is "any f with zero and return", so why not pick the canonical, initial, inductively defined such thing? > > In any case, I prefer Maybe here as well because it's > straightforward and simple. Every other abstraction is just a > lift away. And that's no coincidence, of course. The whole point of inductive definition is to, er, induce such lifts to other settings with /at least/ the same structure. The point was well made to me by James McKinna, years ago, when he suggested that we mediate Epigram's system of "views" via datatypes: the cheap way of abstracting over "all predicates closed under this and that" is to consider the initial one, ie the inductively defined thing with this and that. A whole bunch of higher-order jiggery-pokery with control operators became plain first-order code at a stroke. So it's not a question of concrete-vs-abstract here. The concrete is by inductive (morally anyway) definition, the most abstract thing you can have. All the best Conor
RSS Feed