Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Weid idea for an AST that could form the basis of a structured editor.
# Concrete syntax:
#
# ```
# let
# pi
# : float/64
# = 3.1415
# identity ||< The polymorphic identity function
# : [ A : Type ||< The input type.
# , a : A ||< The input.
# ] -> A
# = [ a ] => a
# compose ||< Compose two functions together.
# : [ A : Type ||< The input type of the first function.
# , B : Type ||< The output type of the first function, and the input type of the second function.
# , C : Type ||< The output type of the second function.
# , a->b : [ a : A ] -> B ||< The first function.
# , b->c : [ b : B ] -> C ||< The second function.
# ] -> C
# = [ a->b, b->c, a ] =>
# b->c [ b = a->b [ a = a ] ]
# in
# (uint/64/to-string/utf8 >> string/utf8/length) 42
# ```
let:
items:
- label: "pi"
type:
global:
label: "float/64"
body:
constant:
data: "..." # TODO: Base-64 encoded float
encoding: "ieee-754/double"
display:
mode: "numeric"
base: 10
- label: "identity"
doc: "The polymorphic identity function."
type:
function/type:
parameters:
- label: "A"
doc: "The input type."
type:
universe: {}
- label: "a"
doc: "The input."
type:
local:
label: "A"
index: 1
body:
local:
label: "A"
index: 1
body:
function/term:
parameters:
- label: "A"
- label: "a"
body:
local:
label: "a"
index: 0
- label: "compose"
doc: "Compose two functions together."
type:
function/type:
parameters:
- label: "A"
doc: "The input type of the first function."
type:
universe: {}
- label: "B"
doc: "The output type of the first function, and the input type of the second function."
type:
universe: {}
- label: "C"
doc: "The output type of the second function."
type:
universe: {}
- label: "a->b"
doc: "The first function."
type:
function/type:
parameters:
- label: "a"
type:
local:
label: "A"
index: 2
body:
local:
label: "B"
index: 1
- label: "b->c"
doc: "The second function."
type:
function/type:
parameters:
- label: "b"
type:
local:
label: "B"
index: 2
body:
local:
label: "C"
index: 1
display:
default:
custom:
name: "forwards"
modes:
- name: "forwards"
render:
- variable:
label: "a->b"
- text: ">>"
- variable:
label: "b->c"
- name: "backwards"
render:
- variable:
label: "b->c"
- text: "<<"
- variable:
label: "a->b"
body:
function/type:
parameters:
- label: "a"
type:
local:
label: "A"
index: 4
body:
local:
label: "C"
index: 3
body:
function/term:
parameters:
- label: "A"
- label: "B"
- label: "C"
- label: "a->b"
- label: "b->c"
- label: "a"
body:
function/elim:
head:
local:
label: "b->c"
index: 1
arguments:
- label: "b"
term:
function/elim:
head:
local:
label: "a->b"
index: 2
arguments:
- label: "a"
term:
local:
label: "a"
index: 0
- label: "take"
type: ...
# Fun { Elem : Type, n : int/64, as : List { Elem } } -> List { Elem }
body:
case: ...
# take 0 _ = []
# take _ [] = []
# take n (x:xs) = x : take (n-1) xs
body:
function/elim:
head:
local:
label: "compose"
index: 1
display:
mode: "forwards"
arguments:
- label: "A"
term:
global:
label: "uint/64"
- label: "B"
term:
global:
label: "string/utf8"
- label: "a->b"
term:
global:
label: "uint/64/to-string/utf8" # TODO: rename parameter
- label: "C"
term:
global:
label: "uint/64"
- label: "a->c"
term:
global:
label: "string/utf8/length" # TODO: rename parameter
- label: "a"
term:
constant:
data: "..." # TODO: Base-64 encoded unsigned integer
display:
mode: "numeric"
base: 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.