Adding Applicative/Functor instances to all Monads in GHC

Hello everyone, I recently went through GHC's source, and discovered there are quite a few instances of Monad that don't have Functor or Applicative instances. Fixing this is very easy by adding the standard instances (pure = return etc.), and will not break code. There is one exception to this: Hoopl defines its own (<*>). However, since it does not seem to have any packages depend on it otherwise, renaming this operator is also easily done (the thing is only used ten times or so). I called it (<*|*>) to complement (|*><*|), but naming should be the least important issue here. Small piece of backstory: The idea behind this is making GHC future-proof for changing Applicative to be a superclass of Monad. However, I think adding the Applicative instances is a good idea regardless of whether this will ever happen, so that's the only thing I'm proposing right now. Greetings, David

Note that I already did this once as part of:
http://hackage.haskell.org/trac/ghc/ticket/4834
However, that never got merged.
So +1.
Bas
On 16 May 2013 13:33, David Luposchainsky
Hello everyone,
I recently went through GHC's source, and discovered there are quite a few instances of Monad that don't have Functor or Applicative instances. Fixing this is very easy by adding the standard instances (pure = return etc.), and will not break code.
There is one exception to this: Hoopl defines its own (<*>). However, since it does not seem to have any packages depend on it otherwise, renaming this operator is also easily done (the thing is only used ten times or so). I called it (<*|*>) to complement (|*><*|), but naming should be the least important issue here.
Small piece of backstory: The idea behind this is making GHC future-proof for changing Applicative to be a superclass of Monad. However, I think adding the Applicative instances is a good idea regardless of whether this will ever happen, so that's the only thing I'm proposing right now.
Greetings, David
_______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries

On 2013-05-16 16:09, Bas van Dijk wrote:
Note that I already did this once as part of: http://hackage.haskell.org/trac/ghc/ticket/4834 However, that never got merged.
That's certainly going to be useful, although the patches may be hard to use due to their age now. I don't want to make this discussion about how useful/probable the new hierarchy proposal change would be, but now that there's a new Haskell Prime team, I thought it would be a good time to get unecessary obstacles out of the way before we even try. If adding Applicatives to GHC works out, we'll have to test how much of Hackage requires similar fixes, and when that is satisfyingly patched up, we can begin to think about retrying your proposal. David

+1
It is about time we finally ripped off this bandaid.
I look forward to the day when I can shed half of the combinators I write in some libs.
-Edward
On May 16, 2013, at 10:19 AM, David Luposchainsky
On 2013-05-16 16:09, Bas van Dijk wrote:
Note that I already did this once as part of: http://hackage.haskell.org/trac/ghc/ticket/4834 However, that never got merged.
That's certainly going to be useful, although the patches may be hard to use due to their age now.
I don't want to make this discussion about how useful/probable the new hierarchy proposal change would be, but now that there's a new Haskell Prime team, I thought it would be a good time to get unecessary obstacles out of the way before we even try. If adding Applicatives to GHC works out, we'll have to test how much of Hackage requires similar fixes, and when that is satisfyingly patched up, we can begin to think about retrying your proposal.
David
_______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries

Also +1. On 16.05.2013 16:39, Edward A Kmett wrote:
+1
It is about time we finally ripped off this bandaid.
I look forward to the day when I can shed half of the combinators I write in some libs.
-Edward
On May 16, 2013, at 10:19 AM, David Luposchainsky
wrote: On 2013-05-16 16:09, Bas van Dijk wrote:
Note that I already did this once as part of: http://hackage.haskell.org/trac/ghc/ticket/4834 However, that never got merged.
That's certainly going to be useful, although the patches may be hard to use due to their age now.
I don't want to make this discussion about how useful/probable the new hierarchy proposal change would be, but now that there's a new Haskell Prime team, I thought it would be a good time to get unecessary obstacles out of the way before we even try. If adding Applicatives to GHC works out, we'll have to test how much of Hackage requires similar fixes, and when that is satisfyingly patched up, we can begin to think about retrying your proposal.
David
_______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries
_______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries
-- Andreas Abel <>< Du bist der geliebte Mensch. Theoretical Computer Science, University of Munich Oettingenstr. 67, D-80538 Munich, GERMANY andreas.abel@ifi.lmu.de http://www2.tcs.ifi.lmu.de/~abel/

+1 -- John Wiegley FP Complete Haskell tools, training and consulting http://fpcomplete.com johnw on #haskell/irc.freenode.net

+1
On Thu, May 16, 2013 at 5:44 PM, John Wiegley
+1
-- John Wiegley FP Complete Haskell tools, training and consulting http://fpcomplete.com johnw on #haskell/irc.freenode.net
_______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries

+1 (yes, please). On Thu, May 16, 2013 at 4:33 AM, David Luposchainsky < dluposchainsky@googlemail.com> wrote:
Hello everyone,
I recently went through GHC's source, and discovered there are quite a few instances of Monad that don't have Functor or Applicative instances. Fixing this is very easy by adding the standard instances (pure = return etc.), and will not break code.
There is one exception to this: Hoopl defines its own (<*>). However, since it does not seem to have any packages depend on it otherwise, renaming this operator is also easily done (the thing is only used ten times or so). I called it (<*|*>) to complement (|*><*|), but naming should be the least important issue here.
Small piece of backstory: The idea behind this is making GHC future-proof for changing Applicative to be a superclass of Monad. However, I think adding the Applicative instances is a good idea regardless of whether this will ever happen, so that's the only thing I'm proposing right now.
Greetings, David
_______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries

On Thu, 16 May 2013, David Luposchainsky wrote:
I recently went through GHC's source, and discovered there are quite a few instances of Monad that don't have Functor or Applicative instances. Fixing this is very easy by adding the standard instances (pure = return etc.), and will not break code.
+1

+1
On May 17, 2013, at 8:10 AM, Henning Thielemann
On Thu, 16 May 2013, David Luposchainsky wrote:
I recently went through GHC's source, and discovered there are quite a few instances of Monad that don't have Functor or Applicative instances. Fixing this is very easy by adding the standard instances (pure = return etc.), and will not break code.
+1
_______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries

On Thu, May 16, 2013 at 01:33:44PM +0200, David Luposchainsky wrote:
I recently went through GHC's source,
If you're talking about GHC itself, rather than the libraries that come with it, then this would be better discussed on the ghc-devs@ list.
and discovered there are quite a few instances of Monad that don't have Functor or Applicative instances.
Small piece of backstory: The idea behind this is making GHC future-proof for changing Applicative to be a superclass of Monad.
I don't think that it helps with this, for 2 reasons: 1. The next time someone adds a Monad, the chances are that they will not think to add the other instances 2. You can't build GHC version X with GHC version Y, where Y > X. Therefore should Applicative become a superclass of Monad, any GHC that has that change would not be able to compile older GHCs (which perhaps are missing Applicative instances) anyway.
However, I think adding the Applicative instances is a good idea regardless of whether this will ever happen, so that's the only thing I'm proposing right now.
I'm a bit ambivalent about this. On the one hand, I wouldn't object to adding instances that are actually useful, but on the other we've currently got problems with the number of symbols in the GHC package DLL on Windows, and I'm not sure anything would be gained by adding instances in many cases. Thanks Ian

[Maybe] this would be better discussed on the ghc-devs@ list I thought that as well, but SPJ said this might be a better place, as it mostly concerns the base libraries. Since the discussion started here, I
Ian, think we shouldn't change lists. (Maybe if individual problems arise those could be discussed individually over there.)
The idea behind this is making GHC future-proof for changing Applicative to be a superclass of Monad.
I don't think that it helps with this, for 2 reasons:
1. The next time someone adds a Monad, the chances are that they will not think to add the other instances
2. You can't build GHC version X with GHC version Y, where Y > X. Therefore should Applicative become a superclass of Monad, any GHC that has that change would not be able to compile older GHCs (which perhaps are missing Applicative instances) anyway. I think this is actually an argument in favour of adding the instances. If the new hierarchy is introduced, old versions will fail to compile, yes, but only unless they have the instances in them already! Suppose 7.8 includes all instances as proposed, and we're going up to 7.14 in a couple of years, and 8.0 introduces the new hierarchy. Everything down to 7.8 will be compilable by 8.0, and most importantly 7.8 will in turn be able to compile GHC < 7.8. From how I see it, adding
That's a valid point. However, I think most people are aware of the issue, so that most fresh code is created appropriately. This is of course just idealistic speculation. One thing I could imagine would be adding a compiler warning for missing Applicative instances, but then again, this is beyond the scope of this proposal (and my Haskell abilities). The manual way of ensuring no non-Applicatives are introduced is of course manual checking, which is a very easy task ("move Applicative to Prelude, fix complaints, move Applicative back"). (Luckily, this is within my abilities) :-) the instances is the only possible way of not breaking backwards compatibility completely, and doing so earlier simplifies the process. David

Hi David, On Fri, May 17, 2013 at 08:32:09PM +0200, David Luposchainsky wrote:
[Maybe] this would be better discussed on the ghc-devs@ list I thought that as well, but SPJ said this might be a better place, as it mostly concerns the base libraries. Since the discussion started here, I think we shouldn't change lists. (Maybe if individual problems arise those could be discussed individually over there.)
Ah, so you're talking about the GHC code /and/ all of the libraries that come with GHC? I'd be in favour of adding the instances to the libraries.
Suppose 7.8 includes all instances as proposed, and we're going up to 7.14 in a couple of years, and 8.0 introduces the new hierarchy. Everything down to 7.8 will be compilable by 8.0
No, it won't. Unrelated to this proposal, you can't build GHC version X with GHC version Y, where Y > X. Thanks Ian -- Ian Lynagh, Haskell Consultant Well-Typed LLP, http://www.well-typed.com/

On 2013-05-17 20:48, Ian Lynagh wrote: Ian,
Ah, so you're talking about the GHC code /and/ all of the libraries that come with GHC? I'd be in favour of adding the instances to the libraries. When I say "GHC" here I mean "everything that comes with GHC and is needed to compile it", more specifically what 'git clone; sync-all get' downloads.
Suppose 7.8 includes all instances as proposed, and we're going up to 7.14 in a couple of years, and 8.0 introduces the new hierarchy. Everything down to 7.8 will be compilable by 8.0
No, it won't. Unrelated to this proposal, you can't build GHC version X with GHC version Y, where Y > X. Oh, I thought what you said was a counter argument because of compatibility issues. In that case you probably meant the change is redundant at this point, which is certainly true for all practical purposes. However, I think it's important that we keep an track of how many changes would be necessary in case the new hierarchy is introduced, and adding those early on will save a ton of work later. This holds for GHC now, and then in the next step for Hackage. In an ideal world, changing the hierarchy (moving a couple of lines from Applicative to Prelude) breaks no code except issuing "redundant import of Applicative" warnings maybe, and the goal of my efforts here is to get as close as possible to that.
David

Hello everyone, I think this proposal has been discussed for only a little above one week, there were +13 votes in favour, none against, and no objections/concerns beyond Ian's comment, whose follow-up message I read as clarifying a misunderstanding and a vote in favour. Should unforseen consequences come up, it is worth mentioning that the AMP includes the changes proposed here in its first phase (i.e. the "patch GHC" part), so I would suggest continuing the discussion in the other thread if necessary. I will also use the AMP thread to open the Trac ticket when some more time has passed (and everything is fine), so in short: this thread merges into the AMP. Greetings, David
participants (12)
-
Andreas Abel
-
Bas van Dijk
-
Carter Schonwald
-
Conal Elliott
-
David Luposchainsky
-
Edward A Kmett
-
Federico Mastellone
-
Henning Thielemann
-
Ian Lynagh
-
John Wiegley
-
Kazu Yamamoto
-
Oliver Charles