I mean powers of <i>ten</i> :)<br><br><div class="gmail_quote">On Dec 8, 2007 10:48 PM, Philip Weaver <<a href="mailto:philip.weaver@gmail.com">philip.weaver@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
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:<br>
<br>
parseInt :: String -> (Expr, String)<br>
parseInt xs = let (digits, rest) = span isDigit <br>
in (EInt (read digits), rest)<br>
<br>
where 'span' is defined in the Prelude. Hope this helps!<br>
<br>
- Phil<br><br><div class="gmail_quote"><div><div></div><div class="Wj3C7c">On Dec 8, 2007 10:03 PM, Ryan Bloor <<a href="mailto:ryanbloor@hotmail.com" target="_blank">ryanbloor@hotmail.com</a>> wrote:<br></div></div>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div></div><div class="Wj3C7c">
<div>hi<br>
<br>
The code below does almost what I want but not quite! It outputs...<font size="2">parseInt "12444a" gives...<br>
[(EInt 1,"2444a"),(EInt 2,"444a"),(EInt 4,"44a"),(EInt 4,"4a"),(EInt 4,"a")]<br></font>
<br>
What I want is: [(EInt 12444, "a")]<br>
<br>
data Expr = EInt {vInt :: Int} -- integer values<br> | EBool {vBool :: Bool} -- boolean values<br>
<br>
parseInt :: Parser <br>parseInt (<font face="">x:xs</font>)<br> | (isDigit x && xs /= []) = [(EInt (read [x]),xs)] ++ parseInt xs<br> | isDigit x && xs == [] = [(EInt (read [x]),[])]<br> | otherwise = []<br>
<br>
Thanks<br>
<br>
Ryan<br>
<br>
<br>
<br>
<br><br><hr>Get closer to the jungle. <a href="http://entertainment.uk.msn.com/tv/realitytv/im-a-celebrity/" target="_blank">I'm a Celebrity Get Me Out Of Here!</a></div></div></div>
<br>_______________________________________________<br>Haskell-Cafe mailing list<br><a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br><a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">
http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br><br></blockquote></div><br>
</blockquote></div><br>