
On Dec 9, 2007 1:01 AM, Ryan Bloor
But what is the right way to indent...? It is so annoying, why does it matter so much! :(
You may read http://en.wikibooks.org/wiki/Haskell/Indentation which tries to explain in a very simple language. -- Felipe.

hi The code below does almost what I want but not quite! It outputs...parseInt "12444a" gives... [(EInt 1,"2444a"),(EInt 2,"444a"),(EInt 4,"44a"),(EInt 4,"4a"),(EInt 4,"a")] What I want is: [(EInt 12444, "a")] data Expr = EInt {vInt :: Int} -- integer values | EBool {vBool :: Bool} -- boolean values parseInt :: Parser parseInt (x:xs) | (isDigit x && xs /= []) = [(EInt (read [x]),xs)] ++ parseInt xs | isDigit x && xs == [] = [(EInt (read [x]),[])] | otherwise = [] Thanks Ryan _________________________________________________________________ Who's friends with who and co-starred in what? http://www.searchgamesbox.com/celebrityseparation.shtml

Well, you're choosing to parse each digit of your integer as a separate
integer, so if you want to combine them after reading you'll need to
multiply by powers of two. Or, you can just read in all the digits in one
'read' command, like this:
parseInt :: String -> (Expr, String)
parseInt xs = let (digits, rest) = span isDigit
in (EInt (read digits), rest)
where 'span' is defined in the Prelude. Hope this helps!
- Phil
On Dec 8, 2007 10:03 PM, Ryan Bloor
hi
The code below does almost what I want but not quite! It outputs...parseInt "12444a" gives... [(EInt 1,"2444a"),(EInt 2,"444a"),(EInt 4,"44a"),(EInt 4,"4a"),(EInt 4,"a")]
What I want is: [(EInt 12444, "a")]
data Expr = EInt {vInt :: Int} -- integer values | EBool {vBool :: Bool} -- boolean values
parseInt :: Parser parseInt (x:xs) | (isDigit x && xs /= []) = [(EInt (read [x]),xs)] ++ parseInt xs | isDigit x && xs == [] = [(EInt (read [x]),[])] | otherwise = []
Thanks
Ryan
------------------------------ Get closer to the jungle. I'm a Celebrity Get Me Out Of Here!http://entertainment.uk.msn.com/tv/realitytv/im-a-celebrity/
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

I mean powers of *ten* :)
On Dec 8, 2007 10:48 PM, Philip Weaver
Well, you're choosing to parse each digit of your integer as a separate integer, so if you want to combine them after reading you'll need to multiply by powers of two. Or, you can just read in all the digits in one 'read' command, like this:
parseInt :: String -> (Expr, String) parseInt xs = let (digits, rest) = span isDigit in (EInt (read digits), rest)
where 'span' is defined in the Prelude. Hope this helps!
- Phil
On Dec 8, 2007 10:03 PM, Ryan Bloor
wrote: hi
The code below does almost what I want but not quite! It outputs...parseInt "12444a" gives... [(EInt 1,"2444a"),(EInt 2,"444a"),(EInt 4,"44a"),(EInt 4,"4a"),(EInt 4,"a")]
What I want is: [(EInt 12444, "a")]
data Expr = EInt {vInt :: Int} -- integer values | EBool {vBool :: Bool} -- boolean values
parseInt :: Parser parseInt (x:xs) | (isDigit x && xs /= []) = [(EInt (read [x]),xs)] ++ parseInt xs | isDigit x && xs == [] = [(EInt (read [x]),[])] | otherwise = []
Thanks
Ryan
------------------------------ Get closer to the jungle. I'm a Celebrity Get Me Out Of Here!http://entertainment.uk.msn.com/tv/realitytv/im-a-celebrity/
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (3)
-
Felipe Lessa
-
Philip Weaver
-
Ryan Bloor