[Haskell-cafe] nested maybes
u.stenzel at web.de
Sun Feb 4 16:50:23 EST 2007
J. Garrett Morris wrote:
> On 2/4/07, Udo Stenzel <u.stenzel at web.de> wrote:
> >> exists s wmap = isJust $ Map.lookup (sort s) wmap >>= find (== s) . snd
> If you're going to write it all on one line, I prefer to keep things
> going the same direction:
Hey, doing it this way saved me a full two keystrokes!!!1
Sure, you're right, everything flowing in the same direction is usually
nicer, and in central Europe, that order is from the left to the right.
What a shame that the Haskell gods chose to give the arguments to (.)
and ($) the wrong order!
> exists s wmap = isJust $ find (==s) . snd =<< Map.lookup (sort s) wmap
> Normally, from there I would be tempted to look for a points-free
> implementation, but in this case I have a strong suspicion that would
> simply be unreadable.
Well, depends on whether we are allowed to define new combinators. I
-- Kleisli composition
infixl 1 @@
(@@) :: Monad m => (a -> m b) -> (b -> m c) -> (a -> m c)
f @@ g = join . liftM g . f
and the resulting
> exists s = Map.lookup (sort s) @@ find (== s) . snd >>> isJust
isn't all that bad. (To be read as: one can get used to it.) I also
think, (@@) and (>>>) belong in the Prelude and (>>>) at type ((a->b) ->
(b->c) -> (b->c)) should be known under a shorter name. Unfortunately,
everything short but (?) is already taken...
Of course, the remaining variable "s" could also be transformed away,
but that's really pointless.
"Never confuse motion with action." -- Ernest Hemingway
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 189 bytes
Desc: Digital signature
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20070204/5f698560/attachment.bin
More information about the Haskell-Cafe