Ticket #8595: 0001-Add-fusion-RULES-for-mapMaybe.patch

File 0001-Add-fusion-RULES-for-mapMaybe.patch, 922 bytes (added by akio, 17 months ago)
  • Data/Maybe.hs

    From 4a84415d39608b147e8ca5ea117e8253ca4d5090 Mon Sep 17 00:00:00 2001
    From: Takano Akio <[email protected]>
    Date: Wed, 20 Nov 2013 16:30:31 +0900
    Subject: [PATCH] Add fusion RULES for mapMaybe
    
    ---
     Data/Maybe.hs |   14 +++++++++++++-
     1 file changed, 13 insertions(+), 1 deletion(-)
    
    diff --git a/Data/Maybe.hs b/Data/Maybe.hs
    index 245e307..fe2a0ab 100644
    a b mapMaybe f (x:xs) = 
    126126 case f x of 
    127127  Nothing -> rs 
    128128  Just r  -> r:rs 
    129  
     129{-# NOINLINE [1] mapMaybe #-} 
     130 
     131{-# RULES 
     132"mapMaybe"     [~1] forall f xs. mapMaybe f xs 
     133                    = build (\c n -> foldr (mapMaybeFB c f) n xs) 
     134"mapMaybeList" [1]  forall f. foldr (mapMaybeFB (:) f) [] = mapMaybe f 
     135  #-} 
     136 
     137{-# NOINLINE [0] mapMaybeFB #-} 
     138mapMaybeFB :: (b -> r -> r) -> (a -> Maybe b) -> a -> r -> r 
     139mapMaybeFB cons f x next = case f x of 
     140  Nothing -> next 
     141  Just r -> cons r next