@hackage / show-combinators

Combinators to write Show instances

Latest0.2.0.0

About

Metadata

  • Last updated , by lyxia
  • License MIT
  • Categories Text Processing
  • Maintained by: lysxia@gmail.com

  • Lottery factor: 0

Links

Installation

Tested Compilers

  1. 8.8.1
  2. 8.6.5
  3. 8.4.4
  4. 8.2.2
  5. 8.0.2
  6. 7.10.3

Readme

Show combinators Hackage Build Status

A minimal set of convenient combinators to write Show instances.

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)