I'm new to functional programming and recently learning at Learn You a Haskell, but when I went through this chapter, I got stuck with the program below:
import Control.Monad.Writer
logNumber :: Int -> Writer [String] Int
logNumber x = Writer (x, ["Got number: " ++ show x])
multWithLog :: Writer [String] Int
multWithLog = do
a <- logNumber 3
b <- logNumber 5
return (a*b)
I saved these lines in a .hs file and but failed to import it into my ghci which complained:
more1.hs:4:15:
Not in scope: data constructor `Writer'
Perhaps you meant `WriterT' (imported from Control.Monad.Writer)
Failed, modules loaded: none.
I examined the type by ":info" command:
Prelude Control.Monad.Writer> :info Writer
type Writer w = WriterT w Data.Functor.Identity.Identity
-- Defined in `Control.Monad.Trans.Writer.Lazy'
From my point of view, this was supposed to be something like "newtype Writer w a ..." so I'm confused about how to feed the data constructor and get a Writer.
I guess it might be a version-related problem and my ghci version is 7.4.1