Use sharing in the Alternative instance of Maybe

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


Hello,

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.

http://hackage.haskell.org/trac/ghc/ticket/5699

Cheers,

Bas



More information about the Libraries mailing list