On Fri, Jul 15, 2011 at 03:01:59PM +0100, Guido Trotter wrote:
> On Fri, Jul 15, 2011 at 2:00 PM, Iustin Pop <ius...@google.com> wrote:
> 
> > Mmm, I can fmap this to make it even more clear:
> >
> >  fmap (flip (-1) 1)
> >
> > as Maybe is a functor instance, and we only need to work on the 'inside'
> > value.
> 
> Not sure this is clear to me. Feel free to apply it this way though.
> Any explanation or nice references? :)

Well, the basic idea is that it bothers me to use "maybe Nothing (Just .
fn)" which does exactly the same thing as "fmap fn" :)

maybe Nothing (Just . fn) means that if the value is nothing, you don't
do anything, and if it's a Just something, you unpack it, then apply fn,
then pack it again in a Maybe. Which is exactly what fmap is supposed to
do - apply a transformation on the value inside the container (if there
is any).

http://hackage.haskell.org/packages/archive/base/latest/doc/html/Prelude.html#t:Functor

Not sure if that is enough explanation, just that "it makes sense" to
use the proper abstraction here…

> > Not really, as the mutation function would be too unreadable?
> >
> >  maybe (False, Nothing) (\n -> n <= ixes_cnt, Just (n - ixes_cnt)) limit
> >
> 
> Not too bad, I can read it, but feel free to live it the other way if
> you prefer.

Will do that, thanks.

iustin

Reply via email to