* Lazy.force
@ 2007-01-02 22:21 Jon Harrop
2007-01-03 8:46 ` [Caml-list] Lazy.force Andrej Bauer
0 siblings, 1 reply; 2+ messages in thread
From: Jon Harrop @ 2007-01-02 22:21 UTC (permalink / raw)
To: caml-list
Could the type checker automatically insert Lazy.force whenever a lazy
expression is used as an eager expression?
--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
Objective CAML for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Caml-list] Lazy.force
2007-01-02 22:21 Lazy.force Jon Harrop
@ 2007-01-03 8:46 ` Andrej Bauer
0 siblings, 0 replies; 2+ messages in thread
From: Andrej Bauer @ 2007-01-03 8:46 UTC (permalink / raw)
To: Jon Harrop; +Cc: caml-list
Jon Harrop wrote:
> Could the type checker automatically insert Lazy.force whenever a lazy
> expression is used as an eager expression?
Consider:
let rec repeat n x =
if n = 0 then [] else x :: (repeat (n-1) x)
let rec sum = function [] -> 0 | x::xs -> x + sum xs
let cow = sum (repeat 1000 (lazy 3))
The typechecker will determine that
repeat : int -> 'a -> 'a list
sum : int list -> int
In the definition of cow it will see that sum, which expects int list,
is applied to int lazy_t list. Where and how should the compiler insert
Lazy.force in this example? Note that it cannot insert anything in the
definition of sum, because later on it might see
let chicken = sum [1;2;3;4]
Best regards,
Andrej
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-01-03 8:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-02 22:21 Lazy.force Jon Harrop
2007-01-03 8:46 ` [Caml-list] Lazy.force Andrej Bauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox