Skip to content

Commit 551c597

Browse files
committed
Add universum-prelude
Problem: in some projects, like `xrefcheck`, we would like to use `universum` without constant explicit `import Universum`. Solution: add a dedicated package that allows doing so. One another way is using mixins feature, but it does not yet work really well (`stack ghci` tends to fail, as well as Haskell language server), so we better look at this feature again at its better times.
1 parent 7fc5dd3 commit 551c597

File tree

8 files changed

+139
-0
lines changed

8 files changed

+139
-0
lines changed

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,43 @@ How to use Universum [↑](#structure-of-this-tutorial)
9999
Okay, enough philosophy. If you want to just start using `universum` and
100100
explore it with the help of compiler, set everything up according to the instructions below.
101101

102+
There are three primary ways.
103+
104+
### Implicit path
105+
106+
Add a dependency on `universum-prelude` that provides `Prelude` with all the `universum` functionality.
107+
108+
Also, replace `base` dependency with `base-noprelude` to avoid conflicts.
109+
110+
### Modern implicit path
111+
112+
Using [mixins](https://cabal.readthedocs.io/en/3.4/cabal-package.html#pkg-field-mixins) feature to provide `Universum` module as `Prelude`. In the configuration this may look like:
113+
114+
```cabal
115+
mixins:
116+
base hiding (Prelude),
117+
universum (Universum as Prelude, Universum.Unsafe as Unsafe)
118+
```
119+
120+
for `.cabal` file and
121+
122+
```yaml
123+
dependencies:
124+
- name: base
125+
mixin: [hiding (Prelude)]
126+
version: "< 4.15"
127+
- name: universum
128+
mixin: [(Universum as Prelude), (Universum.Unsafe as Unsafe)]
129+
```
130+
131+
for `package.yaml`.
132+
133+
Note that at the moment, the mixins feature is not widely supported by the Haskell ecosystem.
134+
135+
### Explicit path
136+
137+
This path for the case when you prefer using explicit `Universum` imports.
138+
102139
Disable the built-in prelude at the top of your file:
103140

104141
```haskell

prelude/CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
0.1
2+
=====
3+
4+
* Initial release.
5+
Providing `Prelude` and `Unsafe` modules.

prelude/LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
Copyright (c) 2021 Serokell
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy
5+
of this software and associated documentation files (the "Software"), to
6+
deal in the Software without restriction, including without limitation the
7+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8+
sell copies of the Software, and to permit persons to whom the Software is
9+
furnished to do so, subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in
12+
all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20+
IN THE SOFTWARE.

prelude/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Universum-prelude
2+
=================
3+
4+
For medium-sized projects, it is tedious to write `import Universum` in every single module, while switching to a project-custom prelude may be not yet desired.
5+
6+
This package re-exports `Universum` module as `Prelude`, effectively allowing implicit import of universum.
7+
When adding a dependncy on `universum-prelude` to your project, you will need to replace `base` dependency with `base-noprelude` to avoid conflicts.
8+
9+
Additionally, `Universum.Unsafe` is re-exported as `Unsafe` module.

prelude/src/Prelude.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module Prelude
2+
( module Universum
3+
) where
4+
5+
import Universum

prelude/src/Unsafe.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module Unsafe
2+
( module Universum.Unsafe
3+
) where
4+
5+
import Universum.Unsafe

prelude/universum-prelude.cabal

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
cabal-version: 2.2
2+
name: universum-prelude
3+
version: 1.0
4+
synopsis: Allows implicit Universum importing.
5+
description: This package exports Prelude module that is just a re-export of Universum.
6+
Can be used with base-noprelude package to implicitly import Universum.
7+
Most suitable for medium-sized projects.
8+
homepage: https://github.com/serokell/universum
9+
license: MIT
10+
license-file: LICENSE
11+
author: @serokell
12+
maintainer: Serokell <hi@serokell.io>
13+
copyright: 2021 Serokell
14+
category: Prelude
15+
stability: stable
16+
build-type: Simple
17+
bug-reports: https://github.com/serokell/universum/issues
18+
extra-doc-files: CHANGES.md
19+
, README.md
20+
21+
source-repository head
22+
type: git
23+
location: git@github.com:serokell/universum.git
24+
25+
common common-options
26+
build-depends: base >= 4.8 && < 5
27+
ghc-options:
28+
-- Source: https://medium.com/mercury-bank/enable-all-the-warnings-a0517bc081c3
29+
-Weverything
30+
-Wno-missing-exported-signatures
31+
-Wno-missing-import-lists
32+
-Wno-missed-specialisations
33+
-Wno-all-missed-specialisations
34+
-Wno-unsafe
35+
-Wno-safe
36+
-Wno-missing-local-signatures
37+
-Wno-monomorphism-restriction
38+
-Wno-implicit-prelude
39+
if impl(ghc >= 8.10.1)
40+
ghc-options: -Wno-prepositive-qualified-module
41+
-Wno-inferred-safe-imports
42+
43+
default-language: Haskell2010
44+
45+
library
46+
import: common-options
47+
hs-source-dirs: src
48+
exposed-modules:
49+
Prelude
50+
Unsafe
51+
52+
build-depends: universum
53+
ghc-options: -Wimplicit-prelude
54+
default-extensions: NoImplicitPrelude

stack.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
resolver: lts-15.11
2+
3+
packages:
4+
- .
5+
- prelude

0 commit comments

Comments
 (0)