Re:Lively Linear Lisp – 'Look Ma, No Garbage' (1991)
by jandrese on Tuesday May 02, 2017 @05:01PM
(#14250541)
So in this example when would you read or write the file?
[ Parent
| on HN ]
Re:Lively Linear Lisp – 'Look Ma, No Garbage' (1991)
by theseoafs on Tuesday May 02, 2017 @05:08PM
(#14250612)
Depends on the implementation of the language. In a typical functional language with linear types, the functions that mutate an object return a "new value" that is conceptually a modified version of the first value. So fleshing out our example:
open : () -> File
close : File -> ()
write : (File, String) -> File
let f: File = open()
let new_f : File = write(f, "Hello world!\n")
close(new_f)
If this seems clumsy or error-prone, notice that you can't accidentally close() f instead of new_f, and you can't forget to close() new_f, so there is actually very little room for error here.
Re:Lively Linear Lisp – 'Look Ma, No Garbage' (1991)
by agumonkey on Tuesday May 02, 2017 @05:14PM
(#14250672)
Wild guess, this is monadic style friendly right ? threading implicit variables (rng, etc) is often used in tutorials.
Re:Lively Linear Lisp – 'Look Ma, No Garbage' (1991)
by theseoafs on Tuesday May 02, 2017 @05:16PM
(#14250699)
Yep -- actually, if you look at how the IO type is defined in Haskell, it looks basically like this (there is an object that represents the "state of the world" that gets threaded through computations).
Re:Lively Linear Lisp – 'Look Ma, No Garbage' (1991)
by agumonkey on Tuesday May 02, 2017 @05:39PM
(#14250871)
Alright. One distinction though is that vanilla IO monad has no logical constraint on consumption. You could technically thread a resource through a function many times and Haskell wouldn't complain. (This is blurry but I had something clear in mind, someone at a Haskeel meetup showed how to enforce constraints on monads through some kind of Phantom Type trick)