Use sharing in the Alternative instance of Maybe
Michael Snoyman
michael at snoyman.com
Wed Dec 14 12:51:50 CET 2011
On Wed, Dec 14, 2011 at 1:49 PM, Bas van Dijk <v.dijk.bas at gmail.com> wrote:
> 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
+1
Out of curiosity, does this actually bypass an extra allocation, or is
GHC smart enough to notice the possibility to share?
Michael
More information about the Libraries
mailing list