How to correctly determine your "company" Prelude

I decided to use my own Prelude for a larger project (containing some libraries and some executables). The prelude does not export some partial functions and does not export some common functions (i.e. From Control.Monad , etc.). However, I struggle with how to do this. I tried:

  • use base-noprelude . Create Prelude.hs in the my-common-module .

  • Same as above, but in my-common-module create My.Prelude . In each other module, create a "foreplay" of the directory, place it in the hs-source-dirs cabal section, create the prelude/Prelude.hs file using import My.Prelude

The problem is that in 1) I can’t just start ghci , since I get conflicting base and my-common-module . In 2) ghci works, cabal repl somehow doesn’t mysteriously fail to “try to use the Prelude module (prelude / Prelude.hs), which is not loaded”. Also, base-noprelude doesn't seem to be like ghcjs , which I want to use for part of the project (code sharing).

It seems to me that the only way to start each file is:

 import Prelude () import My.Prelude 

or

 {-# LANGUAGE NoImplicitPrelude #-} -- or extensions: NoImplicitPrelude in .cabal ... import My.Prelude 

The option 'extensions: NoImplicitPrelude' seems to me better, because importing any file requires My.Prelude , otherwise it will not work. Did I miss some obvious way to achieve a custom Prelude while working with cabal repl and ghcjs at the same time?

Update: base-noprelude works with GHCJS when I manually delete the re-export of GHC.Event.

Update: Well, I spent some time with this, and I should have spent more. It seems to me that 1) this is the right way. cabal repl works (thanks Yuras), ghci needs to be loaded using ghci -hide-package base and works too.

+5
source share
1 answer

I ended up with this setup, which seems to work:

  • Create a custom my-prelude . This package exports Prelude , may contain other modules, it may depend on the base . You may need to use {-# LANGUAGE NoImplicitPrelude #-} in some modules to avoid circular dependencies. For instance. you may want individual orphan instances to be defined and exported by your custom Prelude in separate files (e.g. Orphans.Lib_aeson ), these files require NoImplicitPrelude .

  • In your main library project, etc. change dependencies in Kabbalah from base to base-noprelude, my-prelude .

What works:

  • cabal repl
  • ghci / runghc works, but you have to start it with ghci -hide-package base ; otherwise a conflict between base and my-prelude

What does not work:

  • cabal repl in the my-prelude .
+3
source

Source: https://habr.com/ru/post/1242841/


All Articles