
Hi, 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 complicated. Any suggestions greatly appreciated type Indent = (Int) spacing :: Int -> Indent spacing n = Nothing spacing n (x:xs) = if (n==1) then (Just n) else spacing n xs where (n > 1) John

On Fri, Dec 4, 2009 at 9:26 PM, John Moore
Hi, 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 complicated.
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
-- Jedaï

On Fri, Dec 04, 2009 at 08:26:52PM +0000, John Moore wrote:
type Indent = (Int) spacing :: Int -> Indent spacing n = Nothing spacing n (x:xs) = if (n==1) then (Just n) else spacing n xs where (n > 1)
Hmm, you seem to be a bit confused. What exactly is spacing supposed to do? What is its type? Your type signature says that it has type Int -> Int, but the second equation spacing n (x:xs) = ... suggests that it takes TWO arguments, with the second being a list of some sort; also, it seems to be returning things of type Maybe Int (Nothing, Just n). So, what is it supposed to do? Is it computing an *amount* of indentation? Is it supposed to take a String and put spaces on the front? or...? -Brent
participants (3)
-
Brent Yorgey
-
Chaddaï Fouché
-
John Moore