[Haskell-beginners] Re: monad nomad gonad gomad

prad prad at towardsfreedom.com
Sat Aug 14 19:51:38 EDT 2010


On Fri, 13 Aug 2010 21:39:33 -0700
prad <prad at towardsfreedom.com> wrote:

> "I think It's time for you to get serious with the monads"
> that's just what i'm going to do!
>
i'm asking the question in this thread because i think it has something
to do with monads though i'm not sure. in fact, the problem seems
completely bizarre to me.

i have a function:

mkTxt :: (IConnection conn) => conn -> String -> [String]
mkTxt conn tS = do
    --zzzz <- readFile "zzpubs.htm"
    let wL          = words (rpNls tS)
        ((f,vL):zz) = gtInx wL ["```"]
        rvL         = reverse vL
    doIns wL rvL
        where doIns wL []     = wL
              doIns wL (v:vs) = do
                  let (f,a:b:ss) = splitAt v wL
                  (doIns f vs) ++ ["aoeeuu"] ++ ss

the program compiles and runs fine.
however, if i remove the comment dashes to allow
zzzz <- readFile "zzpubs.htm"

the compiler produces what is to me an incomprehensible rationale for
an error:

====
 gadit.hs:103:4:
    Couldn't match expected type `IO String'
           against inferred type `[String]'
    In a stmt of a 'do' expression: zzzz <- readFile "zzpubs.htm"
    In the expression:
        do { zzzz <- readFile "zzpubs.htm";
             let wL = words (rpNls tS)
                 ((f, vL) : zz) = gtInx wL ...
                 ....;
             doIns wL rvL }
    In the definition of `mkTxt':
        mkTxt conn tS
                = do { zzzz <- readFile "zzpubs.htm";
                       let wL = ...
                           ....;
                       doIns wL rvL }
                where
                    doIns wL [] = wL
                    doIns wL (v : vs)
                            = do { let ...;
                                   .... }
====

i don't do anything with zzzz!!
it merely is the name i'm giving to the monadic computation to read in
a file. in fact, it has nothing to do with the rest of the function
because i don't use it at all.

why is the compiler complaining?


-- 
In friendship,
prad

                                      ... with you on your journey
Towards Freedom
http://www.towardsfreedom.com (website)
Information, Inspiration, Imagination - truly a site for soaring I's




More information about the Beginners mailing list