Feature Proposal: GHC Flag for implicit external Prelude

Hey all, I would like to propose a very minor flag to add to GHC. I would like GHC to have a --with-prelude flag, which would specify an alternate Prelude to use instead of the default Haskell prelude. This would have an effect similar to -XNoImplicitPrelude and an additional import MyNewPrelude in the source file. It might be a *little* different semantically, as a qualified import would disable the original implicit import, just like it does with the default Haskell prelude. The benefit this would have is that this would give alternate preludes a more first-class status. Instead of having to import an alternative prelude everywhere, you could just have a ghc-options: --with-prelude=... flag in your *.cabal file, and have a different prelude be used. This is important for my own work, as I highly prefer other preludes for my non-library development; I think this is a feature which will be very useful as Haskell develops and we try to figure out how to get rid of the warts in the current Prelude. In order to specify the actula module, I propose that you just pass the module name as the --with-prelude argument. You could thus invoke GHC like this: ghc --with-prelude=MyNewPrelude Main.hs Then, the same rules apply for figuring out which MyNewPrelude module you are referring to as if you had written a `import MyNewPrelude` statement in the file. I am willing to implement this for GHC if people agree that this is a useful flag (or at least agree that isn't not a *bad* idea). What are your thoughts on this proposal? -- Andrew

That sounds reasonable to me. I’d use –prelude-is as the flag, by analogy with –main-is; see http://www.haskell.org/ghc/docs/latest/html/users_guide/options-phases.html#... Simon From: Haskell-Cafe [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of Andrew Gibiansky Sent: 15 July 2014 04:23 To: Haskell Cafe Subject: [Haskell-cafe] Feature Proposal: GHC Flag for implicit external Prelude Hey all, I would like to propose a very minor flag to add to GHC. I would like GHC to have a --with-prelude flag, which would specify an alternate Prelude to use instead of the default Haskell prelude. This would have an effect similar to -XNoImplicitPrelude and an additional import MyNewPrelude in the source file. It might be a little different semantically, as a qualified import would disable the original implicit import, just like it does with the default Haskell prelude. The benefit this would have is that this would give alternate preludes a more first-class status. Instead of having to import an alternative prelude everywhere, you could just have a ghc-options: --with-prelude=... flag in your *.cabal file, and have a different prelude be used. This is important for my own work, as I highly prefer other preludes for my non-library development; I think this is a feature which will be very useful as Haskell develops and we try to figure out how to get rid of the warts in the current Prelude. In order to specify the actula module, I propose that you just pass the module name as the --with-prelude argument. You could thus invoke GHC like this: ghc --with-prelude=MyNewPrelude Main.hs Then, the same rules apply for figuring out which MyNewPrelude module you are referring to as if you had written a `import MyNewPrelude` statement in the file. I am willing to implement this for GHC if people agree that this is a useful flag (or at least agree that isn't not a bad idea). What are your thoughts on this proposal? -- Andrew

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 +1. Sounds great. Agree with SPJ in that you should call it -prelude-is. - -- Alexander alexander@plaimi.net https://secure.plaimi.net/~alexander -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iF4EAREIAAYFAlPE83wACgkQRtClrXBQc7WaXwD+I/1AdXaYeSCFgzdjWDWE7Xmj WWfV0D2BXSR6XZm7CXYA/jWPxwzNLFX5R7n+dxAPJO5hhAesIp6lkOk0TjB/emua =Fz/U -----END PGP SIGNATURE-----

+1 on original proposal and SPJ's amendment. If this existed today, I would plan to use it the first few weeks when teaching an intro Haskell course this fall.
Thanks!
On Jul 15, 2014, at 5:25 AM, Alexander Berntsen
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256
+1. Sounds great. Agree with SPJ in that you should call it -prelude-is.
- -- Alexander alexander@plaimi.net https://secure.plaimi.net/~alexander -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iF4EAREIAAYFAlPE83wACgkQRtClrXBQc7WaXwD+I/1AdXaYeSCFgzdjWDWE7Xmj WWfV0D2BXSR6XZm7CXYA/jWPxwzNLFX5R7n+dxAPJO5hhAesIp6lkOk0TjB/emua =Fz/U -----END PGP SIGNATURE----- _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

I'd just like to suggest that -prelude-is MyPrelude smartly avoid
breakage when building MyPrelude.hs
On Tue, Jul 15, 2014 at 5:45 AM, Richard Eisenberg
+1 on original proposal and SPJ's amendment. If this existed today, I would plan to use it the first few weeks when teaching an intro Haskell course this fall.
Thanks!
On Jul 15, 2014, at 5:25 AM, Alexander Berntsen
wrote: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256
+1. Sounds great. Agree with SPJ in that you should call it -prelude-is.
- -- Alexander alexander@plaimi.net https://secure.plaimi.net/~alexander -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iF4EAREIAAYFAlPE83wACgkQRtClrXBQc7WaXwD+I/1AdXaYeSCFgzdjWDWE7Xmj WWfV0D2BXSR6XZm7CXYA/jWPxwzNLFX5R7n+dxAPJO5hhAesIp6lkOk0TjB/emua =Fz/U -----END PGP SIGNATURE----- _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Good call, David. It probably makes sense for --prelude-is MyPrelude to
just act like -XNoImplicitPrelude when in the context
ghc --prelude-is MyPrelude MyPrelude.hs
That way it can be used as a flag in a cabal package that contains the
prelude to be used.
I will try to start working on a patch for this in the next couple of weeks
:)
-- Andrew
On Tue, Jul 15, 2014 at 9:15 AM, David Thomas
I'd just like to suggest that -prelude-is MyPrelude smartly avoid breakage when building MyPrelude.hs
On Tue, Jul 15, 2014 at 5:45 AM, Richard Eisenberg
wrote: +1 on original proposal and SPJ's amendment. If this existed today, I would plan to use it the first few weeks when teaching an intro Haskell course this fall.
Thanks!
On Jul 15, 2014, at 5:25 AM, Alexander Berntsen
wrote: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256
+1. Sounds great. Agree with SPJ in that you should call it -prelude-is.
- -- Alexander alexander@plaimi.net https://secure.plaimi.net/~alexander -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iF4EAREIAAYFAlPE83wACgkQRtClrXBQc7WaXwD+I/1AdXaYeSCFgzdjWDWE7Xmj WWfV0D2BXSR6XZm7CXYA/jWPxwzNLFX5R7n+dxAPJO5hhAesIp6lkOk0TjB/emua =Fz/U -----END PGP SIGNATURE----- _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

One more tiny tiny point: please make it
-prelude-is
and NOT
--prelude-is
so that it matches with -main-is. (Note the number of dashes.)
In general, the anarchy of whether to use one dash or two is annoying, and I think that the parallel with -main-is helps to make the decision easy for this new flag.
Thanks!
Richard
On Jul 15, 2014, at 12:38 PM, Andrew Gibiansky
Good call, David. It probably makes sense for --prelude-is MyPrelude to just act like -XNoImplicitPrelude when in the context
ghc --prelude-is MyPrelude MyPrelude.hs
That way it can be used as a flag in a cabal package that contains the prelude to be used.
I will try to start working on a patch for this in the next couple of weeks :)
-- Andrew
On Tue, Jul 15, 2014 at 9:15 AM, David Thomas
wrote: I'd just like to suggest that -prelude-is MyPrelude smartly avoid breakage when building MyPrelude.hs On Tue, Jul 15, 2014 at 5:45 AM, Richard Eisenberg
wrote: +1 on original proposal and SPJ's amendment. If this existed today, I would plan to use it the first few weeks when teaching an intro Haskell course this fall.
Thanks!
On Jul 15, 2014, at 5:25 AM, Alexander Berntsen
wrote: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256
+1. Sounds great. Agree with SPJ in that you should call it -prelude-is.
- -- Alexander alexander@plaimi.net https://secure.plaimi.net/~alexander -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iF4EAREIAAYFAlPE83wACgkQRtClrXBQc7WaXwD+I/1AdXaYeSCFgzdjWDWE7Xmj WWfV0D2BXSR6XZm7CXYA/jWPxwzNLFX5R7n+dxAPJO5hhAesIp6lkOk0TjB/emua =Fz/U -----END PGP SIGNATURE----- _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On 07/14/2014 11:23 PM, Andrew Gibiansky wrote:
Hey all,
I would like to propose a very minor flag to add to GHC. I would like GHC to have a --with-prelude flag, which would specify an alternate Prelude to use instead of the default Haskell prelude.
This would have an effect similar to -XNoImplicitPrelude and an additional
import MyNewPrelude
in the source file. It might be a /little/ different semantically, as a qualified import would disable the original implicit import, just like it does with the default Haskell prelude.
To play devil's advocate, I don't think this is a good idea. It moves information that is fundamentally local (which library imports a module requires) into global state: magic flags that must be passed to the build system for anything to work. It would be super annoying for an {IDE, coworker, ...} to have to analyze your build system just to figure out which functions are in scope. We went down this road once before with -fglasgow-exts. Eventually, we all realized it was much better to place the required extensions in pragmas at the top of the file.

On 2014-07-15 19:30, Michael Orlitzky wrote:
On 07/14/2014 11:23 PM, Andrew Gibiansky wrote:
Hey all,
I would like to propose a very minor flag to add to GHC. I would like GHC to have a --with-prelude flag, which would specify an alternate Prelude to use instead of the default Haskell prelude.
This would have an effect similar to -XNoImplicitPrelude and an additional
import MyNewPrelude
in the source file. It might be a /little/ different semantically, as a qualified import would disable the original implicit import, just like it does with the default Haskell prelude.
[--snip--]
We went down this road once before with -fglasgow-exts. Eventually, we all realized it was much better to place the required extensions in pragmas at the top of the file.
Except "we" don't :). "We" use flags in the .cabal file. Or, at least I do. Explicitness certainly sometimes has great value, but not always. Regards,

2014-07-15 20:34 GMT+02:00 Bardur Arantsson
On 2014-07-15 19:30, Michael Orlitzky wrote:
On 07/14/2014 11:23 PM, Andrew Gibiansky wrote:
Hey all,
I would like to propose a very minor flag to add to GHC. I would like GHC to have a --with-prelude flag, which would specify an alternate Prelude to use instead of the default Haskell prelude.
This would have an effect similar to -XNoImplicitPrelude and an additional
import MyNewPrelude
in the source file. It might be a /little/ different semantically, as a qualified import would disable the original implicit import, just like it does with the default Haskell prelude.
[--snip--]
We went down this road once before with -fglasgow-exts. Eventually, we all realized it was much better to place the required extensions in pragmas at the top of the file.
Except "we" don't :). "We" use flags in the .cabal file. Or, at least I do. Explicitness certainly sometimes has great value, but not always.
And the problem exists already for other modules than Prelude, i.e. different libraries can export the same modules. The libraries are selected via cabal or via package-qualified imports (and I think the former is preferred).

Personally I put all the flags in each file. That way I can know what
features I'm needing at each use-site. Most of my files have only 1-2
flags. Others have 30.
It is important to me to know where I'm leaning on things like
FlexibleInstances that can make inference for users worse if I don't do so
carefully.
It also lets me load up individual modules as I'm working from ghci
directly rather than rebuild the entire package.
This is, of course, a matter of style, so tastes vary.
-Edward
On Tue, Jul 15, 2014 at 2:34 PM, Bardur Arantsson
On 2014-07-15 19:30, Michael Orlitzky wrote:
On 07/14/2014 11:23 PM, Andrew Gibiansky wrote:
Hey all,
I would like to propose a very minor flag to add to GHC. I would like GHC to have a --with-prelude flag, which would specify an alternate Prelude to use instead of the default Haskell prelude.
This would have an effect similar to -XNoImplicitPrelude and an additional
import MyNewPrelude
in the source file. It might be a /little/ different semantically, as a qualified import would disable the original implicit import, just like it does with the default Haskell prelude.
[--snip--]
We went down this road once before with -fglasgow-exts. Eventually, we all realized it was much better to place the required extensions in pragmas at the top of the file.
Except "we" don't :). "We" use flags in the .cabal file. Or, at least I do. Explicitness certainly sometimes has great value, but not always.
Regards,
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Another problem with making it (cabal) global is that you have to
separate the alternative Prelude (and the modules it depends on) from
the rest of the modules. Otherwise you would have an circular
dependency by importing the new Prelude in the new Prelude you are
defining.
For project specific preludes I can think of two options. Separate
into a package/library, which will probably be more trouble than it
would solve in the first place. Alternatively there could be a
mechanism for excluding the automatic new Prelude import, which would
make things only more complicated. Either way it seems that it would
make things only more difficult if you want a prelude tailored to a
specific project.
Lars
On Tue, Jul 15, 2014 at 7:30 PM, Michael Orlitzky
On 07/14/2014 11:23 PM, Andrew Gibiansky wrote:
Hey all,
I would like to propose a very minor flag to add to GHC. I would like GHC to have a --with-prelude flag, which would specify an alternate Prelude to use instead of the default Haskell prelude.
This would have an effect similar to -XNoImplicitPrelude and an additional
import MyNewPrelude
in the source file. It might be a /little/ different semantically, as a qualified import would disable the original implicit import, just like it does with the default Haskell prelude.
To play devil's advocate, I don't think this is a good idea. It moves information that is fundamentally local (which library imports a module requires) into global state: magic flags that must be passed to the build system for anything to work.
It would be super annoying for an {IDE, coworker, ...} to have to analyze your build system just to figure out which functions are in scope.
We went down this road once before with -fglasgow-exts. Eventually, we all realized it was much better to place the required extensions in pragmas at the top of the file.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

If you want a prelude tailored to a specific project, you don't need
this extension at all. Just create a module named Prelude in your
project.
Actually, given that, I'm not sure what the actual value of this flag
would be. What does it add over just putting a Prelude module in your
project? I guess it would work better for the case when you want a
pre-packaged Prelude replacement, instead of a custom one. But in
that case, be very sure this flag supports loading the Prelude module
from an installed package, instead of from source.
On Wed, Jul 16, 2014 at 3:46 AM, L Corbijn
Another problem with making it (cabal) global is that you have to separate the alternative Prelude (and the modules it depends on) from the rest of the modules. Otherwise you would have an circular dependency by importing the new Prelude in the new Prelude you are defining.
For project specific preludes I can think of two options. Separate into a package/library, which will probably be more trouble than it would solve in the first place. Alternatively there could be a mechanism for excluding the automatic new Prelude import, which would make things only more complicated. Either way it seems that it would make things only more difficult if you want a prelude tailored to a specific project.
Lars
On Tue, Jul 15, 2014 at 7:30 PM, Michael Orlitzky
wrote: On 07/14/2014 11:23 PM, Andrew Gibiansky wrote:
Hey all,
I would like to propose a very minor flag to add to GHC. I would like GHC to have a --with-prelude flag, which would specify an alternate Prelude to use instead of the default Haskell prelude.
This would have an effect similar to -XNoImplicitPrelude and an additional
import MyNewPrelude
in the source file. It might be a /little/ different semantically, as a qualified import would disable the original implicit import, just like it does with the default Haskell prelude.
To play devil's advocate, I don't think this is a good idea. It moves information that is fundamentally local (which library imports a module requires) into global state: magic flags that must be passed to the build system for anything to work.
It would be super annoying for an {IDE, coworker, ...} to have to analyze your build system just to figure out which functions are in scope.
We went down this road once before with -fglasgow-exts. Eventually, we all realized it was much better to place the required extensions in pragmas at the top of the file.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

I worked a bit (not too much to this point) with adding toolage, and I have
to say I agree with those above who say that things should be explicit if
possible, since every special case makes the entry barrier of new tools a
little bit higher. The more uniform we can go with features the better.
2014-07-16 16:51 GMT+02:00 Carl Howells
If you want a prelude tailored to a specific project, you don't need this extension at all. Just create a module named Prelude in your project.
Actually, given that, I'm not sure what the actual value of this flag would be. What does it add over just putting a Prelude module in your project? I guess it would work better for the case when you want a pre-packaged Prelude replacement, instead of a custom one. But in that case, be very sure this flag supports loading the Prelude module from an installed package, instead of from source.
On Wed, Jul 16, 2014 at 3:46 AM, L Corbijn
wrote: Another problem with making it (cabal) global is that you have to separate the alternative Prelude (and the modules it depends on) from the rest of the modules. Otherwise you would have an circular dependency by importing the new Prelude in the new Prelude you are defining.
For project specific preludes I can think of two options. Separate into a package/library, which will probably be more trouble than it would solve in the first place. Alternatively there could be a mechanism for excluding the automatic new Prelude import, which would make things only more complicated. Either way it seems that it would make things only more difficult if you want a prelude tailored to a specific project.
Lars
On Tue, Jul 15, 2014 at 7:30 PM, Michael Orlitzky
wrote: On 07/14/2014 11:23 PM, Andrew Gibiansky wrote:
Hey all,
I would like to propose a very minor flag to add to GHC. I would like GHC to have a --with-prelude flag, which would specify an alternate Prelude to use instead of the default Haskell prelude.
This would have an effect similar to -XNoImplicitPrelude and an additional
import MyNewPrelude
in the source file. It might be a /little/ different semantically, as a qualified import would disable the original implicit import, just like it does with the default Haskell prelude.
To play devil's advocate, I don't think this is a good idea. It moves information that is fundamentally local (which library imports a module requires) into global state: magic flags that must be passed to the build system for anything to work.
It would be super annoying for an {IDE, coworker, ...} to have to analyze your build system just to figure out which functions are in scope.
We went down this road once before with -fglasgow-exts. Eventually, we all realized it was much better to place the required extensions in pragmas at the top of the file.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Wed, Jul 16, 2014 at 10:51 AM, Carl Howells
If you want a prelude tailored to a specific project, you don't need this extension at all. Just create a module named Prelude in your project.
Do you know how to load a project like that in ghci? With cabal repl I get the following error: Top level: attempting to use module ‘Prelude’ (src/Prelude.hs) which is not loaded https://github.com/aavogt/preludeFlag is what I tried Regards, Adam

Hi, Am Mittwoch, den 16.07.2014, 11:25 -0400 schrieb adam vogt:
On Wed, Jul 16, 2014 at 10:51 AM, Carl Howells
wrote: If you want a prelude tailored to a specific project, you don't need this extension at all. Just create a module named Prelude in your project.
Do you know how to load a project like that in ghci? With cabal repl I get the following error:
Top level: attempting to use module ‘Prelude’ (src/Prelude.hs) which is not loaded
https://github.com/aavogt/preludeFlag is what I tried
That might well be a bug in GHC. Try to reproduce it without cabal (i.e. find out what options "cabal repl" passes to GHC) and report it at http://hackage.haskell.org/trac/ghc/ticket/ Greetings, Joachim -- Joachim “nomeata” Breitner mail@joachim-breitner.de • http://www.joachim-breitner.de/ Jabber: nomeata@joachim-breitner.de • GPG-Key: 0xF0FBF51F Debian Developer: nomeata@debian.org

+1
I was actually looking for a feature like that few days ago!
On Jul 15, 2014 4:24 AM, "Andrew Gibiansky"
Hey all,
I would like to propose a very minor flag to add to GHC. I would like GHC to have a --with-prelude flag, which would specify an alternate Prelude to use instead of the default Haskell prelude.
This would have an effect similar to -XNoImplicitPrelude and an additional
import MyNewPrelude
in the source file. It might be a *little* different semantically, as a qualified import would disable the original implicit import, just like it does with the default Haskell prelude.
The benefit this would have is that this would give alternate preludes a more first-class status. Instead of having to import an alternative prelude everywhere, you could just have a ghc-options: --with-prelude=... flag in your *.cabal file, and have a different prelude be used. This is important for my own work, as I highly prefer other preludes for my non-library development; I think this is a feature which will be very useful as Haskell develops and we try to figure out how to get rid of the warts in the current Prelude.
In order to specify the actula module, I propose that you just pass the module name as the --with-prelude argument. You could thus invoke GHC like this:
ghc --with-prelude=MyNewPrelude Main.hs
Then, the same rules apply for figuring out which MyNewPrelude module you are referring to as if you had written a `import MyNewPrelude` statement in the file.
I am willing to implement this for GHC if people agree that this is a useful flag (or at least agree that isn't not a *bad* idea).
What are your thoughts on this proposal?
-- Andrew
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (15)
-
adam vogt
-
Alexander Berntsen
-
Alois Cochard
-
Andrew Gibiansky
-
Bardur Arantsson
-
Carl Howells
-
David Thomas
-
Edward Kmett
-
Joachim Breitner
-
L Corbijn
-
Michael Orlitzky
-
Richard Eisenberg
-
Robin Palotai
-
Simon Peyton Jones
-
Vo Minh Thu