From ef810f28545631e25210787ce48cc6c6e98c7057 Mon Sep 17 00:00:00 2001 From: fr33domlover Date: Fri, 3 Jun 2016 09:12:33 +0000 Subject: [PATCH] Add simple Display class for showing-as-strict-Text --- src/Text/Display.hs | 44 ++++++++++++++++++++++++++++++++++++++++++++ vervis.cabal | 1 + 2 files changed, 45 insertions(+) create mode 100644 src/Text/Display.hs diff --git a/src/Text/Display.hs b/src/Text/Display.hs new file mode 100644 index 0000000..1fc7450 --- /dev/null +++ b/src/Text/Display.hs @@ -0,0 +1,44 @@ +{- This file is part of Vervis. + - + - Written in 2016 by fr33domlover . + - + - ♡ Copying is an act of love. Please copy, reuse and share. + - + - The author(s) have dedicated all copyright and related and neighboring + - rights to this software to the public domain worldwide. This software is + - distributed without any warranty. + - + - You should have received a copy of the CC0 Public Domain Dedication along + - with this software. If not, see + - . + -} + +-- | 'Show' is often used for human-friendly visualization of Haskell values, +-- but there are problems with it: +-- +-- 1. It's supposed to be used for generating text that can also be parsed back +-- into a Haskell value, i.e. 'Read' instances should match the 'Show' ones +-- 2. Auto-generated 'Show and 'Read' often doesn't result with the +-- human-friendly display you want, and if you write a 'Show' instance +-- manually, and you ever need a 'Read' one, you'll need to write it +-- manually too +-- 3. 'Show' uses 'String' while often you want to work with other string-like +-- types, such as strict 'Text' +-- 4. All the pretty printing tools are very structured and use 'String' too, +-- while all I want is a simple value-to-text thing +-- +-- I could generalize here and provide a generic 'Display' 2-param class that +-- can be used with lazy Text and ByteString and any other target type and so +-- on, but instead, at least for now, I'm filling just the missing piece I +-- need: Frieldly display as strict 'Text'. +module Text.Display + ( Display (..) + ) +where + +import Prelude + +import Data.Text (Text) + +class Display a where + display :: a -> Text diff --git a/vervis.cabal b/vervis.cabal index f63f262..dc5fd84 100644 --- a/vervis.cabal +++ b/vervis.cabal @@ -68,6 +68,7 @@ library Formatting.CaseInsensitive Network.SSH.Local Text.Blaze.Local + Text.Display Text.FilePath.Local Text.Jasmine.Local Web.PathPieces.Local