Betr: [clean-list] toInt badness for Clean newbie
Marco Kesseler
m.kesseler@xs4all.nl
Mon, 28 Jun 2004 12:57:56 +0200
Well,
I don't think there should be an error message in this case. It makes
sense to skip some whitespace here and there during conversion, as long
as there's no confusion about interpretation of the string.
And for cases that the string really contains no integer representation,
there should be the possibility to throw an exception (one of my
favourite subjects), as dealing with (Bool, Int) all the time is not
really something to look forward to.
I don't think that proof will buy you much, as 90% of these conversions
are bound to happen at the edges of the system, where either GUI or I/O
provide you with raw strings.
Regards,
Marco
> -----Original Message-----
> From: clean-list-admin@cs.kun.nl
> [mailto:clean-list-admin@cs.kun.nl] On Behalf Of
> erik.zuurbier@tiscali.nl
> Sent: maandag 28 juni 2004 11:32
> To: clean-list@cs.kun.nl
> Subject: Betr: [clean-list] toInt badness for Clean newbie
>
>
> 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
>
>
>
>
>
>
> _______________________________________________
> clean-list mailing list
> clean-list@cs.kun.nl http://www.cs.kun.nl/mailman/listinfo/clean-list
>