I have been trying to compile Haskell code all day – again – involving Control.Monad.Writer. Here is a code example that won't compile from Learn You a Haskell:
import Control.Monad.Writer
gcd' :: Int -> Int -> Writer [String] Int
gcd' a b
| b == 0 = do
tell ["Finished with " ++ show a]
return a
| otherwise = do
tell [show a ++ " mod " ++ show b ++ " = " ++ show (a `mod` b)]
gcd' b (a `mod` b)
I receive this error:
No instance for (Show (Writer [String] Int))
arising from a use of `print'
Possible fix:
add an instance declaration for (Show (Writer [String] Int))
In a stmt of an interactive GHCi command: print it
I have tried compiling code my teacher wrote today also involving Control.Monad.Writer but nothing works.
I am using Ubuntu 12.04, gedit, and GHC 7.4.1.
All the Writer monad programs from Learn You a Haskell have failed to compile, and I am pretty stuck as it is.