alpaca-lang / alpaca

Functional programming inspired by ML for the Erlang VM
Other
1.44k stars 48 forks source link

clarify - nominal or structural type system #265

Closed ORESoftware closed 5 years ago

ORESoftware commented 5 years ago

Sorry if I missed this in the readme - but if it's not there it should be added - does Alpaca use a nominal type system or structural?

j14159 commented 5 years ago

It would probably be most appropriate to call it a structural type system but I'd caution that without a notion of subtyping (as yet), that might not have a ton of meaning for lots of people 😄 As mentioned in other places I've been considering 1ML for a sort of structural approach to subtyping as well.

ORESoftware commented 5 years ago

What do you mean by "subtyping"?

j14159 commented 5 years ago

In something like Java:

interface A {
    public int a(int someInput);
}

// B subtypes A using names, "nominal subtyping":
class B implements A {
    public int a(int someInput) { ... }
}

Whereas, in my limited understanding of 1ML, we might be able to do this in Alpaca at some point:

type a = {
  val a: fn int -> int
}

// Looks nominal, is actually structural, totally acceptable:
let b1 = {
  let a someInput = ...
} : a

// Looks properly structural:
let b2 = {
  let a someInput = ...
} : {
  val a: fn int -> int
}