[Haskell-beginners] truncate results depend on strict/lazy
Bryan Vicknair
bryanvick at gmail.com
Mon Sep 9 19:59:24 CEST 2013
On Mon, Sep 09, 2013 at 01:34:24PM -0400, Mihai Maruseac wrote:
> On Mon, Sep 9, 2013 at 1:26 PM, Bryan Vicknair <bryanvick at gmail.com> wrote:
> > Deep in a WAI web app, I have a function that converts a String from a web form
> > like "0.12" to an Int 12. Converting "0.12" to the Float 0.12 is working.
> > However, converting the Float 0.12 to the Int 12 does not work as expected
> > unless I use the trace function.
>
> Not answering your question but can't you read . drop 1 . dropWhile
> (/= '.') $ "0.12" ?
That would work for the specific input of "0.xyz", but in general, the input
string may encode a float with an arbitrary number of digits on both sides of
the decimal.
In reality, the range is probaby from 0.10 to 1.99, so I considered writing a
parser for just that range, and I may still, but this behavior is so surprising
to me that I feel like I need to understand it.
More information about the Beginners
mailing list