Last active
April 3, 2023 09:18
-
-
Save leque/611fb0326350de16763a6de8fb7febf0 to your computer and use it in GitHub Desktop.
Flexiblly Extend Nested Structures with OCaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
inspired by | |
- Flexiblly Extend Nested Structures - "Trees that Grow" in TypeScript | |
https://dev.to/igrep/flexiblly-extend-nested-structures-trees-that-grow-in-typescript-4347 | |
- 入れ子構造を自由に拡張する – TypeScript版「Trees that Grow」 (Japanese translation of above article) | |
https://eng-blog.iij.ad.jp/archives/18900 | |
*) | |
type 'a literal = [`Literal of int * 'lit] | |
constraint 'a = <literal: 'lit; ..> | |
type 'a variable = [`Variable of string * 'var] | |
constraint 'a = <variable: 'var; ..> | |
type 'a set_variable = [`SetVariable of string * 'expr * 'sv] | |
constraint 'a = <expression: 'expr; set_variable: 'sv; ..> | |
type 'a func = [`Func of string * 'expr * 'func] | |
constraint 'a = <expression: 'expr; func: 'func; ..> | |
type 'a call_func = [`CallFunc of 'expr * 'expr * 'call_func] | |
constraint 'a = <expression: 'expr; call_func: 'call_func; ..> | |
module Full = struct | |
type ext = < literal: unit | |
; variable: unit | |
; set_variable : unit | |
; func : unit | |
; call_func : unit | |
; expression : t | |
> | |
and 'a t_ = ['a literal | 'a variable | 'a set_variable | 'a func | 'a call_func] | |
and t = ext t_ | |
end | |
module NoFunc = struct | |
type ext = < literal: unit | |
; variable: unit | |
; set_variable : unit | |
; expression : t | |
> | |
and 'a t_ = ['a literal | 'a variable | 'a set_variable ] | |
and t = ext t_ | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment