What is a type and effect system?

后端 未结 2 1833
南方客
南方客 2021-02-02 15:33

The Wikipedia article on Effect system is currently just a short stub and I\'ve been wondering for a while as to what is an effect system.

  • Are there any languages
2条回答
  •  醉酒成梦
    2021-02-02 16:21

    A "type and effect system" describes not only the kinds of values in a program, but the changes in those values. "Typestate" checking is a related idea.

    An example might be a type system that tracks file handles: instead of having a function close with return type void, the type system would record the effect of close as disposing of the file resource—any attempt to read from or write to the file after calling close would become a type error.

    I'm not aware of any type and effect system appearing in a mainstream programming language. They have been used to define static analyses (for example, it's quite natural to define an analysis for proper locking/unlocking in terms of effects). As such, effect systems are usually defined using inference schemes rather than concrete syntax. You could imagine a syntax looking something like

    File open(String name) [+File]; // open creates a new file handle
    void close(File f)     [-f]   ; // close destroys f 
    

    If you want to learn more, the following papers might be interesting (fair warning: the papers are quite theoretical).

    • Types for Atomicity: Static Checking and Inference for Java. Flanagan, Freund, Lipshin, and Qadeer.
    • Enforcing High-Level Protocols in Low-Level Software. Robert DeLine and Manuel Fändrich.
    • Type and Effect Systems. Nielson and Nielson.

提交回复
热议问题