File: README.md

package info (click to toggle)
haskell-show-combinators 0.2.0.0-4
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 92 kB
  • sloc: haskell: 116; makefile: 6
file content (19 lines) | stat: -rw-r--r-- 770 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Show combinators [![Hackage](https://img.shields.io/hackage/v/show-combinators.svg)](https://hackage.haskell.org/package/show-combinators) [![Build Status](https://travis-ci.org/Lysxia/show-combinators.svg)](https://travis-ci.org/Lysxia/show-combinators)

A minimal set of convenient combinators to write `Show` instances.

```haskell
data MyType a
  = C a a                   -- a regular constructor
  | a :+: a                 -- an infix constructor
  | R { f1 :: a, f2 :: a }  -- a record

infixl 4 :+:

instance Show a => Show (MyType a) where
  showsPrec = flip precShows where
    precShows (C a b) = showCon "C" @| a @| b
    precShows (c :+: d) = showInfix ":+:" 4 c d
    precShows (R {f1 = e, f2 = f}) =
      showRecord "R" ("f1" .=. e &| "f2" .=. f)
```