
5 Apr
2004
5 Apr
'04
11:52 a.m.
I've found a funny way to fuse functions given to map and filter without RULES pragma: toSelect = (,) Just fromSelect = uncurry mapMaybe transformFirst f (x, y) = (f x, y) maybe f = transformFirst (\g x -> g x >>= f) map f = maybe (Just . f) filter f = maybe (\x -> if f x then Just x else Nothing) test :: [Int] test = fromSelect (map (*2) (filter (<10) (map (+3) (toSelect [1,3,4,6,8])))) Everything looks like obvious application of filter and map, but GHC inline (*2), (<10), (+3) (with -O flag) :^). -- Best regards, RB.