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

erik.zuurbier@tiscali.nl erik.zuurbier@tiscali.nl
Mon, 28 Jun 2004 11:31:47 +0200


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?
>

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)

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.

Regards Erik Zuurbier   


_____________________________________________________________________

Bent u toe aan sneller en goedkoper internet? 
Ga dan naar http://adsl.tiscali.nl