The pretty-types package

[ Tags: bsd3, library, text ] [ Propose Tags ]

Please see README.md


[Skip to Readme]

Properties

Versions 0.1.0.0, 0.1.0.1, 0.1.0.2, 0.1.0.3, 0.1.1.0, 0.2.0.0, 0.2.1.0, 0.2.2.0, 0.2.2.1, 0.2.3.0, 0.2.3.1 (info)
Change log ChangeLog.md
Dependencies base (>=4.9 && <5), mtl (>=2.2 && <3), tagged (>=0.8 && <1) [details]
License BSD3
Copyright 2016 Sven Heyll
Author Sven Heyll
Maintainer sven.heyll@gmail.com
Category Text
Home page https://github.com/sheyll/pretty-types#readme
Source repository head: git clone https://github.com/sheyll/pretty-types
Uploaded Sat Sep 17 00:45:17 UTC 2016 by SvenHeyll
Distributions LTSHaskell:0.2.3.1, NixOS:0.2.3.1, Stackage:0.2.3.1, Tumbleweed:0.2.3.1
Downloads 503 total (13 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2016-09-17 [all 1 reports]
Hackage Matrix CI

Modules

[Index]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


Readme for pretty-types-0.2.3.1

[back to package description]

Build Status Hackage

Type Pretty Printing

A tiny eDSL, not unlike ErrorMessage for TypeErrors to pretty print types, especially uninhabited types.

This Example will render this table:

+-------+-----+------------+
|  col 1|col 2|       col 3|
+-------+-----+------------+
|   2423|  451|       21234|
| 242322|   42|         n/a|
|      0| 4351|      623562|
|   4351|  n/a|         n/a|
|      0| 4351|      623562|
+-------+-----+------------+

From this code:

module Main (main) where

import Data.Type.Pretty
import GHC.TypeLits
import Data.Kind
import Data.Proxy

main :: IO ()
main = putStrLn $ showPretty (Proxy :: Proxy TestTable)

type TestTable =
  'MyTable         '[MyCol "col 1" 7, MyCol "col 2" 5, MyCol "col 3" 12]
          '[ MyRow '[2423           ,451             ,21234]
           , MyRow '[242322         ,42]
           , MyRow '[0              ,4351            ,623562]
           , MyRow '[4351]
           , MyRow '[0              ,4351            ,623562]
           ]

data MyTable = MyTable [Type] [Type]
data MyCol :: Symbol -> Nat -> Type
data MyRow :: [Nat] -> Type


type instance ToPretty ('MyTable cols rows) =
           PrettyManyIn (PutStr "+") (RowSepLine cols)
      <$$> PrettyManyIn (PutStr "|") (TableHeading cols)
      <$$> PrettyManyIn (PutStr "+") (RowSepLine cols)
      <$$> PrettyHigh   (TableRows cols rows)
      <$$> PrettyManyIn (PutStr "+") (RowSepLine cols)

type family TableHeading (cols :: [Type]) :: [PrettyType]
type instance TableHeading '[] = '[]
type instance TableHeading (MyCol title width ': r) =
  PutStrW width title  ': TableHeading  r

type family
   RowSepLine (cols :: [Type]) :: [PrettyType] where
   RowSepLine '[] = '[]
   RowSepLine (MyCol title width ': r) =
     PrettyOften width (PutStr "-") ': RowSepLine  r

type family
  TableRows (cols :: [Type]) (rows :: [Type]) :: [PrettyType] where
  TableRows cols '[] = '[]
  TableRows cols (MyRow cells ': rest ) =
    PrettyManyIn (PutStr "|") (TableCells cols cells) ': TableRows cols rest

type family
  TableCells (cols :: [Type]) (cells :: [Nat]) :: [PrettyType] where
  TableCells '[] cells = '[]
  TableCells (MyCol title width ': cols) (value ': cells) =
    PutNatW width value ':  TableCells cols cells
  TableCells (MyCol title width ': cols) '[] =
    PutStrW width "n/a" ':  TableCells cols '[]