
15 Dec
2011
15 Dec
'11
5:02 a.m.
Christian Maeder
Am 14.12.2011 13:17, schrieb Bas van Dijk:
On 14 December 2011 12:51, Michael Snoyman
wrote: Out of curiosity, does this actually bypass an extra allocation, or is GHC smart enough to notice the possibility to share?
With optimizations on, GHC seems to be smart enough. Since the optimized core of:
plus1 Nothing r = r plus1 (Just x) _ = Just x
I suggest to directly write this using case:
l <|> r = case l of Nothing -> r Just _ -> l
Why not plus1 Nothing r = r plus1 l@(Just x) _ = l or the equivalent written with <|>? -- Jón Fairbairn Jon.Fairbairn@cl.cam.ac.uk