Use sharing in the Alternative instance of Maybe

Bas van Dijk v.dijk.bas at
Wed Dec 14 12:49:05 CET 2011


When looking at the Alternative instance of Maybe I noticed that the
<|> combinator doesn't share it's first argument when it could. So I
propose to make the following change:

 instance Alternative Maybe where
     empty = Nothing
-    Nothing <|> p = p
-    Just x <|> _ = Just x
+    Nothing <|> r = r
+    l       <|> _ = l

Since this isn't a change in the API, I guess this doesn't need to go
through the library submission process.



More information about the Libraries mailing list