Commit 3ca7e487 authored by David Terei's avatar David Terei
Browse files

Merge pull request #13 from ivan-m/add_instances

Add NFData and Eq instances
parents 2c41eb0e 3e9c0eab
......@@ -30,7 +30,8 @@ Library
exposed-modules:
Text.PrettyPrint
Text.PrettyPrint.HughesPJ
build-depends: base >= 3 && < 5
build-depends: base >= 3 && < 5,
deepseq >= 1.1 && < 1.4
extensions: CPP, BangPatterns
ghc-options: -Wall -fwarn-tabs
......
......@@ -75,8 +75,10 @@ module Text.PrettyPrint.HughesPJ (
) where
#endif
import Data.Monoid ( Monoid(mempty, mappend) )
import Data.String ( IsString(fromString) )
import Control.DeepSeq ( NFData(rnf) )
import Data.Function ( on )
import Data.Monoid ( Monoid(mempty, mappend) )
import Data.String ( IsString(fromString) )
-- ---------------------------------------------------------------------------
-- The Doc calculus
......@@ -236,6 +238,24 @@ instance Show Doc where
(ribbonsPerLine style)
txtPrinter cont doc
instance Eq Doc where
(==) = (==) `on` render
instance NFData Doc where
rnf Empty = ()
rnf (NilAbove d) = rnf d
rnf (TextBeside td i d) = rnf td `seq` rnf i `seq` rnf d
rnf (Nest k d) = rnf k `seq` rnf d
rnf (Union ur ul) = rnf ur `seq` rnf ul
rnf NoDoc = ()
rnf (Beside ld s rd) = rnf ld `seq` rnf s `seq` rnf rd
rnf (Above ud s ld) = rnf ud `seq` rnf s `seq` rnf ld
instance NFData TextDetails where
rnf (Chr c) = rnf c
rnf (Str str) = rnf str
rnf (PStr str) = rnf str
-- ---------------------------------------------------------------------------
-- Values and Predicates on GDocs and TextDetails
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment