chaddai.fouche at gmail.com
Sat Dec 5 03:34:56 EST 2009
On Fri, Dec 4, 2009 at 9:26 PM, John Moore <john.moore54 at gmail.com> wrote:
> I'm a bit stuck. I want to indent my answer by using a count function
> to indent my answer. Say for example I want to show the levels in a simple
> arithmethic expression.
> like 3*(4+5)
> I want to be able to print out :
> 4+5 = 9
> 3*9 = 27 (notice the indentation as I go through an expression.
> I tried this but it a mess, I tried to use prettyprint but this seemed very
I'm not sure I really understand what your problem is...
If you just want to indent a String, it is easy to do with :
> indent :: Int -> String -> String
> indent n s = replicate n ' ' ++ s
If you want to use this with your evaluation of a small arithmetic
language, I would suggest making your evaluator returns a list of its
reductions (with the Writer Monad maybe) and use :
> zipWith indent [2,4..] reductionsList
More information about the Beginners