Skip to content

Instantly share code, notes, and snippets.

@23Skidoo
Created July 4, 2011 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 23Skidoo/1063476 to your computer and use it in GitHub Desktop.
Save 23Skidoo/1063476 to your computer and use it in GitHub Desktop.
Sharing map (cleaned-up Core listing)
sharingMap1 :: [([a], a, Maybe a)] -> (# Bool, [a] #)
sharingMap1 [] = (# False, [] #);
sharingMap1 ((ds_diz, y1_adI, Nothing):ys) =
let (# ww1_skq, ww2_skr #) = sharingMap1 ys
in case ww1_skq of {
False -> (# False, ds_diz #);
True -> (# True, (y1_adI:ww2_skr) #)
}
sharingMap1 ((ds_diz, y1_adI, Just y2):ys) =
let (# ww1_skq, ww2_skr #) = sharingMap1 ys
in (# True, (y2:ww2_skr) #)
sharingMap :: (a -> Maybe a) -> [a] -> Maybe [a]
sharingMap f xs =
case sharingMap1 (zip3 (tails xs) xs (map f xs))
of _ { (# m, ww2_skr #) ->
case m of _ {
False -> Nothing
True -> Just ww2_skr
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment