Tuesday, February 16, 2016

1+2

1+2
We have:
  • A type Int (that has a compile time equivalent).
  • A self-declaring name system so that we have WCTL producing something internal that is roughly:
    • ``1 = magic “1”;
    • ``2 = magic “2”;
  • [note that the double ` means that the name can not be redeclared.]
  • The + operator converts to something internal that is roughly:
    • Semigroup.reqdProp.binop.default(1,2)
      [but it’s not a textual translation: no operators involved.]
  • We have a Tuple which is a List(Type)=>Type.
  • And, of course, Type is a Type (in a higher Universe, but we ignore that).
  • So we need Proc, a Tuple[Type Type]=>Type
  • And List, a Type=>Type
  • And we need Atom, a Type [but we don’t need the self-declaring names starting with a “.”.]
  • Int conformsTo Semigroup [in the default way in this case].
  • .binop.default has type Tuple[X X]=>X for some X conformsTo Semigroup
  • So we need to find a type X that is the unique type which 1 and 2 belong to, which conformsTo Semigroup, and which is below any other such (in the isA hierarchy). Yes: it’s an initial object in an obvious (ahem) category. And the answer is … Int.
  • So we somehow get Int.behaviour.Semigroup.binop.default(1,2) [I’m a bit vague about how this happens].
  • Which converts to Int.property.add(1,2)
  • As a .property of Int, add has to be implemented for each implementation
  • Both 1 and 2 are created using the Int64 implementation
  • So we call Int64.property.add(1,2), and check for overflow and finding none, convert the Int64 result to Int (conceptually) and return that.
  • That being all, we call Printable.reqdProp.toString and print that string (since Int conformsTo Printable).

So writing just enough of the compiler for 1+2 will not be trivial.

No comments:

Post a Comment