The Word type (in kind lang) looks like this:
type Word ~ (size: Nat) {
e ~ (size = Nat.zero),
o<size: Nat>(pred: Word(size)) ~ (size = Nat.succ(size)),
i<size: Nat>(pred: Word(size)) ~ (size = Nat.succ(size)),
}
The syntax is defined here.
All it says is:
type Name (A: Par0, B: Par1 ...) ~ (i: Idx0, j: Idx1 ...) { ctor0(field0: Fld0, field1: Fld1 ...) ~ (i = id0, j = idx1 ...) ctor1(field0: Fld0, field1: Fld1 ...) ~ (i = id0, j = idx1 ...) ... }
Declares an inductive algebraic datatype. A simple datatype starts with the type keyword, followed by its name, followed by any number of parameters ("static polymorphic types"). Inside {} follows any number of constructors, each one is followed by its fields.
As an example, the following type, in Haskell:
data List a = Nil | Cons a (List a)
Can be written in Kind as:
type List (A: Type) { nil cons(head: A, tail: List(A)) }
... Where ~ (it's optional) stands for any number of indices ("dynamic polymorphic types"). In the constructor, its fields are also optionally followed by ~ and its concrete indices.
The Word
type is used all over, mainly like this:
type U8 {
new(value: Word(8))
}
That makes sense to me, we have a type record with a value field which is type Word(8)
. But how does the Word
type itself work? I don't follow. Take one constructor line, like this:
o<size: Nat>(pred: Word(size)) ~ (size = Nat.succ(size))
What does that mean? Passing the pred: Word(size)
seems like an infinite loop.
Another type with similar definition is Bits
:
type Bits {
e,
o(pred: Bits),
i(pred: Bits),
}
Maybe it has to do with self types?