Skip to content

Commit

Permalink
Add universum-prelude
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Martoon-00 committed Aug 12, 2021
1 parent b640ec3 commit 1d1347d
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 0 deletions.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,43 @@ How to use Universum [↑](#structure-of-this-tutorial)
Okay, enough philosophy. If you want to just start using `universum` and
explore it with the help of compiler, set everything up according to the instructions below.

There are three primary ways.

### Implicit path

Add a dependency on `universum-prelude` that provides `Prelude` with all the `universum` functionality.

Also, replace `base` dependency with `base-noprelude` to avoid conflicts.

### Modern implicit path

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:

```cabal
mixins:
base hiding (Prelude),
universum (Universum as Prelude, Universum.Unsafe as Unsafe)
```

for `.cabal` file and

```yaml
dependencies:
- name: base
mixin: [hiding (Prelude)]
version: "< 4.15"
- name: universum
mixin: [(Universum as Prelude), (Universum.Unsafe as Unsafe)]
```
for `package.yaml`.

Note that at the moment, the mixins feature is not widely supported by the Haskell ecosystem.

### Explicit path

This path for the case when you prefer using explicit `Universum` imports.

Disable the built-in prelude at the top of your file:

```haskell
Expand Down
5 changes: 5 additions & 0 deletions prelude/CHANGES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
0.1
=====

* Initial release.
Providing `Prelude` and `Unsafe` modules.
20 changes: 20 additions & 0 deletions prelude/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright (c) 2021 Serokell

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
9 changes: 9 additions & 0 deletions prelude/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Universum-prelude
=================

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.

This package re-exports `Universum` module as `Prelude`, effectively allowing implicit import of universum.
When adding a dependncy on `universum-prelude` to your project, you will need to replace `base` dependency with `base-noprelude` to avoid conflicts.

Additionally, `Universum.Unsafe` is re-exported as `Unsafe` module.
5 changes: 5 additions & 0 deletions prelude/src/Prelude.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Prelude
( module Universum
) where

import Universum
5 changes: 5 additions & 0 deletions prelude/src/Unsafe.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Unsafe
( module Universum.Unsafe
) where

import Universum.Unsafe
54 changes: 54 additions & 0 deletions prelude/universum-prelude.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
cabal-version: 2.2
name: universum-prelude
version: 1.0
synopsis: Allows implicit Universum importing.
description: This package exports Prelude module that is just a re-export of Universum.
Can be used with base-noprelude package to implicitly import Universum.
Most suitable for medium-sized projects.
homepage: https://github.com/serokell/universum
license: MIT
license-file: LICENSE
author: @serokell
maintainer: Serokell <[email protected]>
copyright: 2021 Serokell
category: Prelude
stability: stable
build-type: Simple
bug-reports: https://github.com/serokell/universum/issues
extra-doc-files: CHANGES.md
, README.md

source-repository head
type: git
location: [email protected]:serokell/universum.git

common common-options
build-depends: base >= 4.8 && < 5
ghc-options:
-- Source: https://medium.com/mercury-bank/enable-all-the-warnings-a0517bc081c3
-Weverything
-Wno-missing-exported-signatures
-Wno-missing-import-lists
-Wno-missed-specialisations
-Wno-all-missed-specialisations
-Wno-unsafe
-Wno-safe
-Wno-missing-local-signatures
-Wno-monomorphism-restriction
-Wno-implicit-prelude
if impl(ghc >= 8.10.1)
ghc-options: -Wno-prepositive-qualified-module
-Wno-inferred-safe-imports

default-language: Haskell2010

library
import: common-options
hs-source-dirs: src
exposed-modules:
Prelude
Unsafe

build-depends: universum
ghc-options: -Wimplicit-prelude
default-extensions: NoImplicitPrelude
4 changes: 4 additions & 0 deletions stack.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
resolver: lts-15.11

packages:
- .
- prelude

0 comments on commit 1d1347d

Please sign in to comment.