1. 14
  1.  

  2. 5

    schema Nat = #{ % >= 0 }

    This is very nice!

    A minor question: what makes schemas different from types?

    1. 3

      Thank you!

      It depends how you define a type I suppose.

      Schemas themselves just define a shape or a predicate to validate data at runtime.

      I think what separates them from “types” is right now I don’t have a way to enforce that a variable conforms to a schema for its entire lifetime. So for example:

      Nat(num) := 0
      

      Doesn’t mean that I can’t do this right after

      num := -1
      

      BUT I have some plans to extend how I use schemas to be more like what I understand contracts in other languages & at that point I think they could qualify as “types” in a dynamic runtime sense but I’m not sure if others would agree.

      So for example this is what I’m currently thinking about.

      num : Nat := 0
      num := -1 // MatchError
      

      Now for the entire life of num it must always conform to the Nat schema, this would be done by injecting runtime checks at all assignments, and there should be ways to optimize this.

      1. 4

        Ah it’s a runtime check! Ok that’s much clearer! For some reason I thought it was outside runtime lol.

    2. 3

      I like the way you present the features, the step-by-step approach with comparisons to JavaScript give a glimpse on the design decisions that you made creating Peacock.