Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CofreeT's Show instance does not work #72

Closed
exergasia opened this issue Jun 11, 2014 · 0 comments
Closed

CofreeT's Show instance does not work #72

exergasia opened this issue Jun 11, 2014 · 0 comments

Comments

@exergasia
Copy link
Collaborator

It spins endlessly and produces an infinite string of repeating "CofreeT (". It's a one line fix but I added a test for it anyway:

diff --git a/free.cabal b/free.cabal
index 86df40e..30ff931 100644
--- a/free.cabal
+++ b/free.cabal
@@ -95,3 +95,12 @@ library
     Control.Monad.Trans.Iter

   ghc-options: -Wall
+
+test-suite CofreeTShowRead
+  hs-source-dirs: test/
+  default-language:   Haskell2010
+  type:           exitcode-stdio-1.0
+  main-is:        CofreeTShowRead.hs
+  build-depends:
+    base                 == 4.*,
+    free
diff --git a/src/Control/Comonad/Trans/Cofree.hs b/src/Control/Comonad/Trans/Cofree.hs
index bdf8ce7..20e6ad3 100644
--- a/src/Control/Comonad/Trans/Cofree.hs
+++ b/src/Control/Comonad/Trans/Cofree.hs
@@ -139,7 +139,7 @@ instance (Functor f, Comonad w) => ComonadCofree f (CofreeT f w) where
   unwrap = tailF . extract . runCofreeT

 instance Show (w (CofreeF f a (CofreeT f w a))) => Show (CofreeT f w a) where
-  showsPrec d w = showParen (d > 10) $
+  showsPrec d (CofreeT w) = showParen (d > 10) $
     showString "CofreeT " . showsPrec 11 w

 instance Read (w (CofreeF f a (CofreeT f w a))) => Read (CofreeT f w a) where
diff --git a/test/CofreeTShowRead.hs b/test/CofreeTShowRead.hs
new file mode 100644
index 0000000..dc471b7
--- /dev/null
+++ b/test/CofreeTShowRead.hs
@@ -0,0 +1,10 @@
+import Control.Comonad.Trans.Cofree
+import Control.Monad
+import System.Exit
+
+main = do
+  let x :: CofreeT Maybe [] Bool
+      x = CofreeT [True :< Nothing]
+      x' :: CofreeT Maybe [] Bool
+      x' = read . show $ x
+  when (x /= x') exitFailure
@ekmett ekmett closed this as completed in ed0d1d3 Jun 15, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant