
J. Garrett Morris wrote:
On 2/4/07, Udo Stenzel
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 sometimes use -- 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. -Udo -- "Never confuse motion with action." -- Ernest Hemingway