Betr: [clean-list] toInt badness for Clean newbie

Jenda Krynicky Jenda@Krynicky.cz
Mon, 26 Jul 2004 14:28:58 +0200


From: erik.zuurbier@tiscali.nl
> Ben Lippmeier wrote:
> 
> >module argh
> >
> >import StdEnv
> >
> >Start :: (Int, Int)
> >Start     = (toInt "100", toInt "100\n")
> >-----
> >
> >$ clm argh -o argh
> >$ ./argh
> >(100,0)
> >Execution: 0.00  Garbage collection: 0.00  Total: 0.00
> >$
> >
> >(100, 0)?
> >That's a little rough, don't you think?

Yep. I think most people would expect
 (100, 100)

> Indeed. The signature of toInt leaves no place for an error message or
> for a boolean indicating succesful conversion. Actually the function
> should not terminate in this case. The quick and dirty solution would
> be to change the type signature (for this instance) to:
> 
> toInt :: String -> (Bool,Int)

That would not be very pleasant to work with.
 
> A slower solution would be to change the compiler so that it demands a
> proof (by Sparkle) that all strings fed to toInt (in this particular
> application) actually have a succesful conversion.

Oh my ... if I understand you right I would have to test whether the 
string I received from GUI contains int and nothing but int in the 
code in such a way that the compiler can prove that by the time the 
string reaches toInt() it's "clean", right? I might as well implement 
the toInt() myself then.

Any reason why toInt() can't mean "skip the whitespace if any, read 
the digits and convert them to an integer, ignore the rest of the 
string" ?

Jenda
===== Jenda@Krynicky.cz === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
	-- Terry Pratchett in Sourcery