I am learning about monads in the book 'Learn You a Haskell for Great Good!' by Miran Lipovaca. I am reading about how the Control.Monad.Writer module exports the Writer w a
type along with its Monad instance and some useful functions for dealing with values of this type.
For the following code:
newtype Writer w a = Writer { runWriter :: (a,w) }
I know that the a
type parameter represents the type of some value, and the w
type parameter represents the type of the attached monoid value. Am I correct in saying that by passing w
and a
to the Writer
type constructor, you get a Writer monad in return, with this monad only having one function which is the runWriter
function?
In the book it says that the runWriter
function takes a tuple that's wrapped in a Writer
newtype and unwraps it, returning a simple tuple. However the type declaration of runWriter
is runWriter :: (a,w)
, it doesn't take any parameters as input. How does runWriter
take a tuple that's wrapped in a newtype and return just a simple tuple?