Yes that if block did get indented incorrectly in the posting. However, I like how the guards work for this, and as soon as I used your recommendation, it started working. Great, my first Haskell program, albeit with a little help, I appreciate it.
David Menendez-2 wrote: > > On Mon, Dec 21, 2009 at 11:14 PM, joeltt <[email protected]> wrote: >> >> I'm trying to write my first Haskell program. The below is the first real >> logic block I've tried to write, unfortunately I get a "The last >> statement >> in a 'do' construct must be an expression" error when loading the method. >> However, the location of this problem isn't very clear. Is there a way to >> get more detailed parse message from Haskell, or can someone tell me >> where >> the problem is (and better "why"?). I don't think I actually need to use >> a >> "do" IO/Monad theme here, but its not clear to me either way. This isn't >> homework, its just for fun... >> >> >> do_solve_iter guess tried = do >> let actual = count_occurences guess >> if guess == actual >> then putStrLn "ANSWER!!" >> else if (find (==actual) tried) == Just actual >> then do >> putStrLn "NO ANSWER!" >> putStrLn tried >> else do >> putStrLn "ITER" >> do_solve_iter actual (actual : tried) > > Assuming your indentation didn't get lost in transmission, your > problem is the line "if guess == actual", which needs to be at the > same level of indentation as "let actual...". As written, the do-block > is terminating after the let-statement, which isn't permitted. > > Also, unless there is more to the function, you don't really need the > outermost do-block at all. You can rewrite it easily as a let...in > expression, or move the definition of actual to a where clause and use > guards to avoid the nested if-expressions. > > > do_solve_iter guess tried > | guess == actual = putStrLn "ANSWER!!" > | find (==actual) tried == Just actual = do > putStrLn "NO ANSWER" > putStrLn tried > | otherwise = do > putStrLn "ITER" > do_solve_iter actual (actual : tried) > where > actual = count_occurences guess > > -- > Dave Menendez <[email protected]> > <http://www.eyrie.org/~zednenem/> > _______________________________________________ > Haskell-Cafe mailing list > [email protected] > http://www.haskell.org/mailman/listinfo/haskell-cafe > > -- View this message in context: http://old.nabble.com/Parse-do-block-problem-tp26883702p26884268.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. _______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
