sdiehl / print

Simple printing with Text
http://www.stephendiehl.com/posts/strings.html
MIT License
11 stars 3 forks source link

Print

Build Status

Simple printing with Text. This is a prototype, not production code.

base             >= 4.6  && <4.10,
text             >= 1.2  && <1.3,
text-format      >= 0.3  && <0.4

Functions

Replaces the Prelude function show:

show :: Show a => a -> String

... with a new one that uses Text.

show :: Show a => a -> Text

Instances

A Text-based Show replacement can be derived with GHC's new -XDeriveAnyClass.

{-# LANGUAGE DeriveAnyClass #-}

data Animal 
  = Dog
  | Cat
  deriving (Generic, Print.Show)

GHCi

GHCI's default printing mechanism can be overloaded by adding the following to your .ghci file. Anything typed at the console will then use the modern print function instead of the Prelude.

import Print
:set -interactive-print=Print.print

Building

Stack (Recommended)

$ stack build
$ stack repl print:exe:Example

Cabal

$ cabal sandbox init
$ cabal install --only-dependencies
$ cabal build
$ cabal repl exe:Example