Fuse functions given to map and filter without RULES pragma
rabeslik at ukr.net
Mon Apr 5 19:52:50 EDT 2004
I've found a funny way to fuse functions given to map and filter without
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
Everything looks like obvious application of filter and map, but GHC inline
(*2), (<10), (+3) (with -O flag) :^).
Best regards, RB.
More information about the Haskell-Cafe