* [Caml-list] Reason why 'for' doesn't work across floats?
@ 2004-01-08 14:11 Richard Jones
2004-01-08 15:03 ` Michal Moskal
0 siblings, 1 reply; 6+ messages in thread
From: Richard Jones @ 2004-01-08 14:11 UTC (permalink / raw)
To: caml-list
Is there a particular reason why I shouldn't be allowed to step over
floats?
# for r = 0. to 9. step 1. do printf "%f" r done;;
--
This expression has type float but is here used with type int
Rich.
--
Richard Jones. http://www.annexia.org/ http://freshmeat.net/users/rwmj
Merjis Ltd. http://www.merjis.com/ - improving website return on investment
http://www.winwinsales.co.uk/ - CRM improvement consultancy
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] Reason why 'for' doesn't work across floats?
2004-01-08 14:11 [Caml-list] Reason why 'for' doesn't work across floats? Richard Jones
@ 2004-01-08 15:03 ` Michal Moskal
2004-01-08 15:47 ` Jacques Carette
2004-01-08 15:47 ` Richard Jones
0 siblings, 2 replies; 6+ messages in thread
From: Michal Moskal @ 2004-01-08 15:03 UTC (permalink / raw)
To: caml-list
On Thu, Jan 08, 2004 at 02:11:52PM +0000, Richard Jones wrote:
> Is there a particular reason why I shouldn't be allowed to step over
> floats?
>
> # for r = 0. to 9. step 1. do printf "%f" r done;;
> --
> This expression has type float but is here used with type int
let f a b = for x = a to b do () done
What type would f have (int -> int -> int or float -> float -> float)?
One would need "for.", which doesn't seem appealing.
--
: Michal Moskal :: http://www.kernel.pl/~malekith : GCS {C,UL}++++$ a? !tv
: When in doubt, use brute force. -- Ken Thompson : {E-,w}-- {b++,e}>+++ h
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] Reason why 'for' doesn't work across floats?
2004-01-08 15:03 ` Michal Moskal
@ 2004-01-08 15:47 ` Jacques Carette
2004-01-08 15:47 ` Richard Jones
1 sibling, 0 replies; 6+ messages in thread
From: Jacques Carette @ 2004-01-08 15:47 UTC (permalink / raw)
To: Michal Moskal, caml-list
Michal Moskal <malekith@pld-linux.org> wrote:
> On Thu, Jan 08, 2004 at 02:11:52PM +0000, Richard Jones wrote:
> > Is there a particular reason why I shouldn't be allowed to step over
> > floats?
> >
> > # for r = 0. to 9. step 1. do printf "%f" r done;;
> > --
> > This expression has type float but is here used with type int
>
> let f a b = for x = a to b do () done
>
> What type would f have (int -> int -> int or float -> float -> float)?
> One would need "for.", which doesn't seem appealing.
Another reason is that
for r = 0. to 9. step 0.001 do printf "%f" r done;;
will not necessary have the expected number of iterations, since 9. will not be 'hit' exactly (numerical round-off
guarantees that). For some loops, the number of times around would change depending on whether all the numbers
involved have exact base 2 representations or not. Very ugly.
After suffering through painful debugging sesions on programs in languages that allow the above type of loops, I am
quite glad that Ocaml does not allow this, even if in this case it is because of typing rather than sound numerical
analysis...
Jacques
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] Reason why 'for' doesn't work across floats?
2004-01-08 15:03 ` Michal Moskal
2004-01-08 15:47 ` Jacques Carette
@ 2004-01-08 15:47 ` Richard Jones
2004-01-08 16:15 ` Artem Prisyznuk
2004-01-09 7:36 ` Florian Hars
1 sibling, 2 replies; 6+ messages in thread
From: Richard Jones @ 2004-01-08 15:47 UTC (permalink / raw)
To: caml-list
On Thu, Jan 08, 2004 at 04:03:58PM +0100, Michal Moskal wrote:
> On Thu, Jan 08, 2004 at 02:11:52PM +0000, Richard Jones wrote:
> > Is there a particular reason why I shouldn't be allowed to step over
> > floats?
> >
> > # for r = 0. to 9. step 1. do printf "%f" r done;;
> > --
> > This expression has type float but is here used with type int
>
> let f a b = for x = a to b do () done
>
> What type would f have (int -> int -> int or float -> float -> float)?
> One would need "for.", which doesn't seem appealing.
Perhaps 'a -> 'a -> 'a ?
Is this much different from the generic-but-not-really < operator in
OCaml?
Rich.
--
Richard Jones. http://www.annexia.org/ http://freshmeat.net/users/rwmj
Merjis Ltd. http://www.merjis.com/ - improving website return on investment
http://www.YouUnlimited.co.uk/ - management courses
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] Reason why 'for' doesn't work across floats?
2004-01-08 15:47 ` Richard Jones
@ 2004-01-08 16:15 ` Artem Prisyznuk
2004-01-09 7:36 ` Florian Hars
1 sibling, 0 replies; 6+ messages in thread
From: Artem Prisyznuk @ 2004-01-08 16:15 UTC (permalink / raw)
To: Richard Jones; +Cc: caml-list
On Thu, 8 Jan 2004 15:47:59 +0000, Richard Jones <rich@annexia.org> wrote:
>> One would need "for.", which doesn't seem appealing.
>
> Perhaps 'a -> 'a -> 'a ?
>
> Is this much different from the generic-but-not-really < operator in
> OCaml?
Operator '<' - defined on any types, it's really polymorph operator.
But operator 'for' not has sences on string type.
--
Artem Prysyznuk
tema@sit.kiev.ua
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] Reason why 'for' doesn't work across floats?
2004-01-08 15:47 ` Richard Jones
2004-01-08 16:15 ` Artem Prisyznuk
@ 2004-01-09 7:36 ` Florian Hars
1 sibling, 0 replies; 6+ messages in thread
From: Florian Hars @ 2004-01-09 7:36 UTC (permalink / raw)
To: caml-list
Richard Jones wrote:
> On Thu, Jan 08, 2004 at 04:03:58PM +0100, Michal Moskal wrote:
>>>let f a b = for x = a to b do () done
>>
>>What type would f have (int -> int -> int or float -> float -> float)?
>
> Perhaps 'a -> 'a -> 'a ?
So how many iterations would
f (Some (fun x -> x < "foobar"), None) (None, Some [| 1.2, 1.4, 1.6|])
perform?
Yours, Florian.
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2004-01-09 7:36 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-01-08 14:11 [Caml-list] Reason why 'for' doesn't work across floats? Richard Jones
2004-01-08 15:03 ` Michal Moskal
2004-01-08 15:47 ` Jacques Carette
2004-01-08 15:47 ` Richard Jones
2004-01-08 16:15 ` Artem Prisyznuk
2004-01-09 7:36 ` Florian Hars
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox