Quick actions

cmd+k|ctrl+k

Navigation

Languages

Demo Linear Types

Snippet info

Language

Ats

Visibility

public

Author

steinwaywhw

Created

2018-04-16T21:29:54Z

Updated

2018-04-16T21:29:54Z

absvtype cake = ptr // declare cake as a linear resource

extern fun produce_cake (): cake      // produce a cake, linear
extern fun take_picture (!cake): void // take a picture of the cake, does not consume it, denoted as !
extern fun eat (cake): void           // eat a cake, consume it

implement main0 () = let 

    val cake = produce_cake ()
    val _ = take_picture (cake) // ok
    val _ = take_picture (cake) // ok 
    val _ = eat (cake)          // ok 
    val _ = eat (cake)          // WRONG: the cake is consumed in the last line.
                                //        it is no longer available in the typing environment at this line. 
in 
end
INFO