[Haskell-cafe] Lazy series [was : Preventing sharing]
tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk
Sat Jan 9 18:42:25 UTC 2016
On Sat, Jan 09, 2016 at 07:22:48PM +0100, Arjen wrote:
> I was thinking of exps as a value (having a non-function type).
> Maybe I'm wrong or just not understanding the issue fully. How do
> you differentiate between expression that are values and those that
> are function applications on arguments?
I'm not sure you really "differentiate" between them. The evaluation of
function arguments just has different consequences when those argument
values are integers than it does when those argument values are functions.
> If I were to print the value of exps, like main = print exps. How
> would I express this? Or is it print's responsibility to evaluate
> the argument?
> Say, exps has type Integer. How does print differentiate between a
> actual value (print 42) and unevaluated expressions (print exps)?
I'm not quite sure what you're asking, but consider the difference between
these two calls to the function id in OCaml.
# let id x = x;;
val id : 'a -> 'a = <fun>
# id (Printf.printf "Hello");;
Hello- : unit = ()
# id (fun () -> Printf.printf "Hello");;
- : unit -> unit = <fun>
The correspond to the following in an imaginary impure Haskell-like
id (print "Hello")
id (\() -> print "Hello")
More information about the Haskell-Cafe