linear-types

Linear types in OCaml

我的未来我决定 提交于 2019-12-22 06:09:09
问题 Rust has a linear type system. Is there any (good) way to simulate this in OCaml? E.g., when using ocaml-lua, I want to make sure some functions are called only when Lua is in a specific state (table on top of stack, etc). Edti : Here's a recent paper about resource polymorphism relevant to the question: https://arxiv.org/abs/1803.02796 回答1: As suggested by John Rivers, you can use a monadic style to represent "effectful" computation in a way that hides the linear constraint in the effect API

Linear types in OCaml

和自甴很熟 提交于 2019-12-05 10:30:28
Rust has a linear type system. Is there any (good) way to simulate this in OCaml? E.g., when using ocaml-lua, I want to make sure some functions are called only when Lua is in a specific state (table on top of stack, etc). Edti : Here's a recent paper about resource polymorphism relevant to the question: https://arxiv.org/abs/1803.02796 As suggested by John Rivers, you can use a monadic style to represent "effectful" computation in a way that hides the linear constraint in the effect API. Below is one example where a type ('a, 'st) t is used to represent computation using a file handle (whose