Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add universum-prelude #242

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, it's completely unfair not to mention the mixin approach. Yes, it breaks some tools and for many people it's a critical downside, but apart from that it sounds like the cleanest solution which one should prefer if they don't care about broken tools.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, I completely forgot that this is also an option and worth enlisting here.


### 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
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 <hi@serokell.io>
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: git@github.com: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