Skip to content

Safer use of datatypes #6

@larsrh

Description

@larsrh

Currently, datatypes are generated as a set of structs that represent the constructors. The datatype itself is generated as any.

Because of how Go's structs and interfaces work, there is really not much of a better approach here.

But we can try to make the "outer shell" a bit safer, and, say, prevent someone passing a number to a function expecting a list.

We could change the way datatypes are generated as follows:

type Nat struct {
  value nat;
}
type nat any;
type Zero struct { };
type Suc struct { A Nat; };
func Suc_dest(p Suc)(Nat) {
  case return q.A;
}
func Mk_zero()(Nat) {
  return Nat{nat(Zero{})};
}
func Mk_suc(A Nat)(Nat) {
  return Nat{nat(Suc{A})};
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions