[commit: packages/pretty] large_docs, master, moretests: Add NFData and Eq instances (3e9c0ea)

git at git.haskell.org git at git.haskell.org
Fri Jan 23 22:48:43 UTC 2015


Repository : ssh://git@git.haskell.org/pretty

On branches: large_docs,master,moretests
Link       : http://git.haskell.org/packages/pretty.git/commitdiff/3e9c0eab6adf4859fd62396111fd2676c95a4997

>---------------------------------------------------------------

commit 3e9c0eab6adf4859fd62396111fd2676c95a4997
Author: Ivan Lazar Miljenovic <ivan.miljenovic at gmail.com>
Date:   Tue Jun 24 19:55:22 2014 +1000

    Add NFData and Eq instances
    
    Eq instance is based via the default rendering in case of differences in
    how they were created.


>---------------------------------------------------------------

3e9c0eab6adf4859fd62396111fd2676c95a4997
 pretty.cabal                     |  3 ++-
 src/Text/PrettyPrint/HughesPJ.hs | 24 ++++++++++++++++++++++--
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/pretty.cabal b/pretty.cabal
index 7714b73..7d71469 100644
--- a/pretty.cabal
+++ b/pretty.cabal
@@ -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
 
diff --git a/src/Text/PrettyPrint/HughesPJ.hs b/src/Text/PrettyPrint/HughesPJ.hs
index 10de760..2a36f07 100644
--- a/src/Text/PrettyPrint/HughesPJ.hs
+++ b/src/Text/PrettyPrint/HughesPJ.hs
@@ -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
 



More information about the ghc-commits mailing list