Skip to content

Commit ba9d202

Browse files
committed
Prepare release 0.0.3.0 (#26)
Prepare v0.0.3.0
1 parent 3aa873c commit ba9d202

File tree

8 files changed

+126
-103
lines changed

8 files changed

+126
-103
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,46 +7,13 @@ on:
77
branches: ["main"]
88

99
jobs:
10-
lint:
11-
name: HLint
12-
runs-on: ubuntu-latest
13-
steps:
14-
- name: Checkout HLint repo
15-
uses: actions/checkout@v2
16-
with:
17-
repository: ndmitchell/hlint
18-
ref: '8e10b5143acf97fbdf9baff40ee2da93881e0bf8'
19-
- name: Set up Haskell
20-
id: setup-haskell
21-
uses: haskell/actions/setup@v1
22-
with:
23-
ghc-version: '9.0.1'
24-
cabal-version: 'latest'
25-
- name: Configure HLint
26-
run: cabal new-configure
27-
- name: Freeze HLint
28-
run: cabal freeze
29-
- name: Cache
30-
uses: actions/[email protected]
31-
with:
32-
path: ${{ steps.setup-haskell.outputs.cabal-store }}
33-
key: ${{ hashFiles('cabal.project.freeze') }}
34-
- name: Build HLint
35-
run: cabal new-install
36-
- name: Checkout text-display
37-
uses: actions/checkout@v2
38-
with:
39-
path: ./text-display
40-
- name: Run HLint
41-
run: |
42-
cd text-display && find src test -name "*.hs" -exec ${{ steps.setup-haskell.outputs.cabal-store }}/../bin/hlint {} +
4310
native:
4411
name: ${{ matrix.ghc }} on ${{ matrix.os }}
4512
runs-on: ${{ matrix.os }}
4613
strategy:
4714
matrix:
4815
os: [ubuntu-latest, macos-latest, windows-latest]
49-
ghc: ['8.8', '8.10', '9.0', '9.2.1']
16+
ghc: ['8.8', '8.10', '9.0', '9.2', '9.4.1']
5017
steps:
5118
- name: Checkout base repo
5219
uses: actions/checkout@v2

.github/workflows/linting.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Linting
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: ["main", "development"]
7+
8+
jobs:
9+
fourmolu:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
14+
- uses: fourmolu/fourmolu-action@v3
15+
with:
16+
pattern: |
17+
src/**/*.hs
18+
test/**/*.hs
19+
20+
hlint:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v2
24+
25+
- name: 'Set up HLint'
26+
uses: rwe/actions-hlint-setup@v1
27+
with:
28+
version: '3.4.1'
29+
30+
- name: 'Run HLint'
31+
uses: rwe/actions-hlint-run@v1
32+
with:
33+
path: '["src/", "test/"]'
34+
fail-on: warning

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# CHANGELOG
22

3-
## [v0.0.3.0] - DD/MM/YYY
3+
## [v0.0.3.0] - 21/08/2022
44

55
This is an experimental release.
66

77
* Support for text-2.0
8-
8+
* Support for GHC 9.4
99

1010
## [v0.0.2.0] – 13/03/2022
1111

@@ -24,3 +24,4 @@ This is an experimental release.
2424
[Unreleased]: https://github.com/kleidukos/text-display/compare/v0.0.1.0...HEAD
2525
[v0.0.1.0]: https://github.com/kleidukos/text-display/releases/tag/v0.0.1.0
2626
[v0.0.2.0]: https://github.com/kleidukos/text-display/releases/tag/v0.0.2.0
27+
[v0.0.3.0]: https://github.com/kleidukos/text-display/releases/tag/v0.0.3.0

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ test: ## Run the test suite
1616
lint: ## Run the code linter (HLint)
1717
@find test src -name "*.hs" | parallel -j $(PROCS) -- hlint --refactor-options="-i" --refactor {}
1818

19+
style: ## Run the code styler (stylish-haskell)
20+
@fourmolu -q --mode inplace test src
21+
@cabal-fmt -i *.cabal
22+
1923
check:
2024
@./scripts/ci-check.sh
2125

fourmolu.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
indentation: 2
2+
comma-style: leading # for lists, tuples etc. - can also be 'leading'
3+
import-export-style: leading
4+
record-brace-space: false # rec {x = 1} vs. rec{x = 1}
5+
indent-wheres: true # 'false' means save space by only half-indenting the 'where' keyword
6+
respectful: true # don't be too opinionated about newlines etc.
7+
haddock-style: single-line # '--' vs. '{-'
8+
newlines-between-decls: 1 # number of newlines between top-level declarations
9+
fixities: []

src/Data/Text/Display.hs

Lines changed: 59 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{-# LANGUAGE DataKinds #-}
2-
{-# LANGUAGE OverloadedStrings #-}
32
{-# LANGUAGE DerivingVia #-}
43
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
4+
{-# LANGUAGE OverloadedStrings #-}
55
{-# LANGUAGE ScopedTypeVariables #-}
66
{-# LANGUAGE StandaloneDeriving #-}
77
{-# LANGUAGE StrictData #-}
@@ -10,51 +10,54 @@
1010
{-# LANGUAGE TypeOperators #-}
1111
{-# LANGUAGE UndecidableInstances #-}
1212

13-
{-|
14-
Module : Data.Text.Display
15-
Copyright : © Hécate Moonlight, 2021
16-
License : MIT
17-
Maintainer : [email protected]
18-
Stability : stable
19-
20-
Use 'display' to produce user-facing text
21-
22-
-}
13+
-- |
14+
-- Module : Data.Text.Display
15+
-- Copyright : © Hécate Moonlight, 2021
16+
-- License : MIT
17+
-- Maintainer : [email protected]
18+
-- Stability : stable
19+
--
20+
-- Use 'display' to produce user-facing text
2321
module Data.Text.Display
2422
( -- * Documentation
2523
display
26-
, Display(..)
27-
, -- * Deriving your instance automatically
28-
ShowInstance(..)
29-
, OpaqueInstance(..)
30-
, -- * Writing your instance by hand
31-
displayParen
32-
-- * Design choices
33-
-- $designChoices
34-
) where
24+
, Display (..)
25+
26+
-- * Deriving your instance automatically
27+
, ShowInstance (..)
28+
, OpaqueInstance (..)
29+
30+
-- * Writing your instance by hand
31+
, displayParen
32+
33+
-- * Design choices
34+
-- $designChoices
35+
)
36+
where
3537

3638
import Control.Exception hiding (TypeError)
3739
import Data.ByteString
40+
import qualified Data.ByteString.Lazy as BL
3841
import Data.Int
3942
import Data.Kind
4043
import Data.List.NonEmpty
44+
import Data.Proxy
4145
import Data.Text (Text)
46+
import qualified Data.Text as T
47+
import qualified Data.Text.Lazy as TL
4248
import Data.Text.Lazy.Builder (Builder)
43-
import Data.Word
44-
import GHC.TypeLits
45-
import qualified Data.ByteString.Lazy as BL
4649
import qualified Data.Text.Lazy.Builder as TB
4750
import qualified Data.Text.Lazy.Builder.Int as TB
4851
import qualified Data.Text.Lazy.Builder.RealFloat as TB
49-
import qualified Data.Text as T
50-
import qualified Data.Text.Lazy as TL
51-
import Data.Proxy
52+
import Data.Word
53+
import GHC.TypeLits
5254

5355
-- | A typeclass for user-facing output.
5456
--
5557
-- @since 0.0.1.0
5658
class Display a where
5759
{-# MINIMAL displayBuilder | displayPrec #-}
60+
5861
-- | Implement this method to describe how to convert your value to 'Builder'.
5962
displayBuilder :: a -> Builder
6063
displayBuilder = displayPrec 0
@@ -91,11 +94,11 @@ class Display a where
9194
-- > → Custom `displayList`
9295
displayList :: [a] -> Builder
9396
displayList [] = "[]"
94-
displayList (x:xs) = displayList' xs ("[" <> displayBuilder x)
97+
displayList (x : xs) = displayList' xs ("[" <> displayBuilder x)
9598
where
9699
displayList' :: [a] -> Builder -> Builder
97-
displayList' [] acc = acc <> "]"
98-
displayList' (y:ys) acc = displayList' ys (acc <> "," <> displayBuilder y)
100+
displayList' [] acc = acc <> "]"
101+
displayList' (y : ys) acc = displayList' ys (acc <> "," <> displayBuilder y)
99102

100103
-- | The method 'displayPrec' allows you to write instances that
101104
-- require nesting. The precedence parameter can be thought of as a
@@ -127,13 +130,13 @@ class Display a where
127130
-- > infix 5 :*: -- arbitrary choice of precedence
128131
-- > instance (Display a, Display b) => Display (Pair a b) where
129132
-- > displayPrec prec (a :*: b) = displayParen (prec > 5) $ displayPrec 6 a <> " :*: " <> displayPrec 6 b
130-
displayPrec
131-
:: Int -- ^ The precedence level passed in by the surrounding context
132-
-> a
133-
-> Builder
133+
displayPrec ::
134+
-- | The precedence level passed in by the surrounding context
135+
Int ->
136+
a ->
137+
Builder
134138
displayPrec _ = displayBuilder
135139

136-
137140
-- | Convert a value to a readable 'Text'.
138141
--
139142
-- === Examples
@@ -159,12 +162,13 @@ instance CannotDisplayBareFunctions => Display (a -> b) where
159162

160163
-- | @since 0.0.1.0
161164
type family CannotDisplayBareFunctions :: Constraint where
162-
CannotDisplayBareFunctions = TypeError
163-
( 'Text "🚫 You should not try to display functions!" ':$$:
164-
'Text "💡 Write a 'newtype' wrapper that represents your domain more accurately." ':$$:
165-
'Text " If you are not consciously trying to use `display` on a function," ':$$:
166-
'Text " make sure that you are not missing an argument somewhere."
167-
)
165+
CannotDisplayBareFunctions =
166+
TypeError
167+
( 'Text "🚫 You should not try to display functions!"
168+
':$$: 'Text "💡 Write a 'newtype' wrapper that represents your domain more accurately."
169+
':$$: 'Text " If you are not consciously trying to use `display` on a function,"
170+
':$$: 'Text " make sure that you are not missing an argument somewhere."
171+
)
168172

169173
-- | 🚫 You should not try to display strict ByteStrings!
170174
--
@@ -185,11 +189,12 @@ instance CannotDisplayByteStrings => Display BL.ByteString where
185189
displayBuilder = undefined
186190

187191
type family CannotDisplayByteStrings :: Constraint where
188-
CannotDisplayByteStrings = TypeError
189-
( 'Text "🚫 You should not try to display ByteStrings!" ':$$:
190-
'Text "💡 Always provide an explicit encoding" ':$$:
191-
'Text "Use 'Data.Text.Encoding.decodeUtf8'' or 'Data.Text.Encoding.decodeUtf8With' to convert from UTF-8"
192-
)
192+
CannotDisplayByteStrings =
193+
TypeError
194+
( 'Text "🚫 You should not try to display ByteStrings!"
195+
':$$: 'Text "💡 Always provide an explicit encoding"
196+
':$$: 'Text "Use 'Data.Text.Encoding.decodeUtf8'' or 'Data.Text.Encoding.decodeUtf8With' to convert from UTF-8"
197+
)
193198

194199
-- | A utility function that surrounds the given 'Builder' with parentheses when the Bool parameter is True.
195200
-- Useful for writing instances that may require nesting. See the 'displayPrec' documentation for more
@@ -237,7 +242,8 @@ instance KnownSymbol str => Display (OpaqueInstance str a) where
237242
newtype ShowInstance (a :: Type)
238243
= ShowInstance a
239244
deriving newtype
240-
( Show -- ^ @since 0.0.1.0
245+
( -- | @since 0.0.1.0
246+
Show
241247
)
242248

243249
-- | This wrapper allows you to rely on a pre-existing 'Show' instance in order to derive 'Display' from it.
@@ -301,9 +307,10 @@ instance Display Text where
301307

302308
-- | @since 0.0.1.0
303309
instance Display a => Display [a] where
304-
{-# SPECIALISE instance Display [String] #-}
305-
{-# SPECIALISE instance Display [Char] #-}
306-
{-# SPECIALISE instance Display [Int] #-}
310+
{-# SPECIALIZE instance Display [String] #-}
311+
{-# SPECIALIZE instance Display [Char] #-}
312+
{-# SPECIALIZE instance Display [Int] #-}
313+
307314
-- In this instance, 'displayBuilder' is defined in terms of 'displayList', which for most types
308315
-- is defined as the default written in the class declaration.
309316
-- But when @a ~ Char@, there is an explicit implementation that is selected instead, which
@@ -373,15 +380,15 @@ deriving via (ShowInstance SomeException) instance Display SomeException
373380

374381
-- | @since 0.0.1.0
375382
instance (Display a, Display b) => Display (a, b) where
376-
displayBuilder (a, b) = "(" <> displayBuilder a <> "," <> displayBuilder b <> ")"
383+
displayBuilder (a, b) = "(" <> displayBuilder a <> "," <> displayBuilder b <> ")"
377384

378385
-- | @since 0.0.1.0
379386
instance (Display a, Display b, Display c) => Display (a, b, c) where
380-
displayBuilder (a, b, c) = "(" <> displayBuilder a <> "," <> displayBuilder b <> "," <> displayBuilder c <> ")"
387+
displayBuilder (a, b, c) = "(" <> displayBuilder a <> "," <> displayBuilder b <> "," <> displayBuilder c <> ")"
381388

382389
-- | @since 0.0.1.0
383390
instance (Display a, Display b, Display c, Display d) => Display (a, b, c, d) where
384-
displayBuilder (a, b, c, d) = "(" <> displayBuilder a <> "," <> displayBuilder b <> "," <> displayBuilder c <> "," <> displayBuilder d <> ")"
391+
displayBuilder (a, b, c, d) = "(" <> displayBuilder a <> "," <> displayBuilder b <> "," <> displayBuilder c <> "," <> displayBuilder d <> ")"
385392

386393
-- $designChoices
387394
--

test/Main.hs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,37 @@
1+
{-# LANGUAGE DataKinds #-}
12
{-# LANGUAGE DerivingVia #-}
23
{-# LANGUAGE OverloadedStrings #-}
34
{-# LANGUAGE TypeApplications #-}
4-
{-# LANGUAGE DataKinds #-}
55
{-# OPTIONS_GHC -fdefer-type-errors -Wno-deferred-type-errors #-}
66

77
module Main where
88

99
import Data.ByteString
1010
import Data.List.NonEmpty
11+
import qualified Data.List.NonEmpty as NE
12+
import qualified Data.Text as T
13+
import Data.Text.Arbitrary
1114
import Test.Hspec
1215
import Test.Hspec.QuickCheck
13-
import Data.Text.Arbitrary
1416
import Test.ShouldNotTypecheck (shouldNotTypecheck)
15-
import qualified Data.List.NonEmpty as NE
16-
import qualified Data.Text as T
1717

1818
import Data.Text.Display
1919

2020
main :: IO ()
2121
main = hspec spec
2222

2323
data AutomaticallyDerived = AD
24-
deriving stock Show
25-
deriving Display via (ShowInstance AutomaticallyDerived)
24+
deriving stock (Show)
25+
deriving (Display) via (ShowInstance AutomaticallyDerived)
2626

2727
data ManualType = MT Int
2828

2929
instance Display ManualType where
3030
displayPrec prec (MT i) = displayParen (prec > 10) $ "MT " <> displayPrec 11 i
3131

3232
data OpaqueType = OpaqueType Int
33-
deriving Display
33+
deriving
34+
(Display)
3435
via (OpaqueInstance "<opaque>" OpaqueType)
3536

3637
spec :: Spec

0 commit comments

Comments
 (0)