From 2f0e4ae8ccbd61d37d3d5fb192183c4d0746b6b9 Mon Sep 17 00:00:00 2001
From: sof <unknown>
Date: Thu, 16 Sep 1999 18:40:05 +0000
Subject: [PATCH] [project @ 1999-09-16 18:40:05 by sof] Added Tree example
 from (older) versions of the Report

---
 ghc/tests/deriving/should_run/drvrun006.hs    | 49 +++++++++++++++++++
 .../deriving/should_run/drvrun006.stdout      |  6 +++
 2 files changed, 55 insertions(+)
 create mode 100644 ghc/tests/deriving/should_run/drvrun006.hs
 create mode 100644 ghc/tests/deriving/should_run/drvrun006.stdout

diff --git a/ghc/tests/deriving/should_run/drvrun006.hs b/ghc/tests/deriving/should_run/drvrun006.hs
new file mode 100644
index 000000000000..3d268019bd13
--- /dev/null
+++ b/ghc/tests/deriving/should_run/drvrun006.hs
@@ -0,0 +1,49 @@
+-- !!! Show/Read deriving example given in the Haskell Report.
+module Main(main) where
+
+infix 4 :^:
+data Tree a 
+  =  Leaf a  | (Tree a) :^: (Tree a)
+     deriving (Show, Read)
+
+val1 :: Tree Int
+val1 = Leaf 2
+
+val2 :: Tree Int
+val2 = Leaf 2 :^: Leaf (-1)
+
+main = do
+  print val1
+  print val2
+
+  print ((read (show val1))::Tree Int)
+  print ((read (show val2))::Tree Int)
+  print ((read (show val1))::Tree Integer)
+  print ((read (show val2))::Tree Integer)
+
+{- What you'll want
+instance (Show a) => Show (Tree a) where
+
+        showsPrec d (Leaf m) = showParen (d >= 10) showStr
+    	  where
+             showStr = showString "Leaf " . showsPrec 10 m
+
+        showsPrec d (u :^: v) = showParen (d > 4) showStr
+    	  where
+             showStr = showsPrec 5 u . 
+                       showString " :^: " .
+                       showsPrec 5 v
+
+instance (Read a) => Read (Tree a) where
+
+	readsPrec d r =  readParen (d > 4)
+			 (\r -> [(u:^:v,w) |
+				 (u,s) <- readsPrec 5 r,
+				 (":^:",t) <- lex s,
+				 (v,w) <- readsPrec 5 t]) r
+
+		      ++ readParen (d > 9)
+			 (\r -> [(Leaf m,t) |
+				 ("Leaf",s) <- lex r,
+				 (m,t) <- readsPrec 10 s]) r
+-}
diff --git a/ghc/tests/deriving/should_run/drvrun006.stdout b/ghc/tests/deriving/should_run/drvrun006.stdout
new file mode 100644
index 000000000000..fe1beeeae0c9
--- /dev/null
+++ b/ghc/tests/deriving/should_run/drvrun006.stdout
@@ -0,0 +1,6 @@
+Leaf 2
+Leaf 2 :^: Leaf (-1)
+Leaf 2
+Leaf 2 :^: Leaf (-1)
+Leaf 2
+Leaf 2 :^: Leaf (-1)
-- 
GitLab