[Haskell-cafe] Lazy series [was : Preventing sharing]
Arjen
arjenvanweelden at gmail.com
Sat Jan 9 18:48:04 UTC 2016
On 01/09/2016 07:42 PM, Tom Ellis wrote:
> 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
> language:
>
> id (print "Hello")
> "Hello"
>
> id (\() -> print "Hello")
> <no output>
>
>
I think I see what you mean. Then in OCaml exps would have type
unit->Int? And to get the value, you would use exps ()?
kind regards, Arjen
More information about the Haskell-Cafe
mailing list