Catena is an experimental statically-typed, concatenative programming language. This file consists of random scribblings and notes related to the same.
copy :: a → a a :: a *R → a a *R
swap :: a b → b a :: a b *R → b a *R
drop :: a → :: a *R → *R
{ 'pop'? }
wrap :: a → [a] :: a *R → [→ a] *R
unwrap :: [*A] → *A :: [→ *A] *R → *A *R
clean :: *A → :: *A *R → *R
apply :: [*A → *B] *A → *B
(= `unwrap` with tighter type?) (no: with wider type!)
bind :: [a *A → *B] a → [*A → *B] :: [a *A → *B] a *R → [*A → *B] *R
{ unneeded? maybe concat replaces this? }
partial-results :: [*A → b *B] → [*A → b [*B]]
{needs better name}
pop :: [a *A:a] → a [*A:a]
push :: a [*A:a] → [a *A:a]
concat :: [*A:a] [*B:b] → [*A:a *B:b]
{ are these even needed? type propagation → if input is homogenous, then
output is too }
pop' :: [a *A] → a [*A]
push' :: a [*A] → [a *A]
concat':: [*A] [*B] → [*A *B]
choose :: a a Bool → a
dip :: [*A → *B] a *A → a *B
dip2 :: [*A → *B] a b *A → a b *B
dip3 :: [*A → *B] a b c *A → a b c *B
foldl :: [a b → a] a [*B:b] → a
foldr :: [b a → a] a [*B:b] → a
map :: [a → b] [*A:a] → [*B:b]
TODO: Step-by-step algorithm detailing how unification between various (A,B) type-vector pairs should work.
(Should Bound be its own "sort"?)
(Bound, Bound) → succeed if equal in value
(Bound, `$`) → fail
(Single, Bound) → bind A←B (substitute Single for Bound)
(Single, Single) → link A=B
(Single, `$`) → fail
(Vector, Bound) → substitute Vector for (Bound, Vector)
(Vector, Single) → substitute Vector for (Single, Vector)
(Vector, Vector) → link A=B {??}
(Vector, `$`) → substitute Vector for nothing (empty match)
(Quot, Quot) → unify A.from with B.from; A.to with B.to
(Quot, `_`) → fail
(`$`, `$`) → succeed
(`$`, `_`) → fail
Otherwise, unify (b,a)
1 :: *R → Num *R
wrap :: a *R → [a] *R
unwrap :: [→ *A] *R → *A *R
unwrap wrap 1 1
The formal grammar of the type system and of valid programs themselves.
# stack-effect ← type-vector "*R" "→" type-vector "*R"
function ← type-vector "→" type-vector
# type-vector ← (single-type)* (type-vector-var)*
type-vector ← (single-type)* (type-vector-var)?
type-vector-var ← type-vector-ho / type-vector-he
type-vector-ho ← type-vector-var' type-clarifier
type-vector-he ← type-vector-var'
type-clarifier ← ":" single-type
single-type ← concrete-type / single-type-var / quotation
quotation ← "[" function "]"
concrete-type ← UppercaseLetter LetterOrDigit+
single-type-var ← LowercaseLetter LetterOrDigit+
type-vector-var' ← "*" UppercaseLetter LetterOrDigit+
LetterOrDigit ← UppercaseLetter / LowercaseLetter / Digit
UppercaseLetter ← (defined by Unicode)
LowercaseLetter ← (defined by Unicode)
Digit ← (defined by Unicode)
(Doesn't include types yet)
program ← program-part? (";" program-part)*
program-part ← assignment / phrase
assignment ← separator? identifier ":=" program separator?
phrase ← separator? ((word / quotation) separator)*
word ← !reserved-word IdentifierChar+
quotation ← "[" phrase "]"
separator ← WhiteSpace+
reserved-word ← ":="
WhiteSpace ← (defined by Unicode)
WordChar ← (Any character not in WhiteSpace, which is not "[", "]" or ";")