Preliminary Sketch for F Natural

I’ve gone back to F♮, but decided to abandon the Perl implementation in favour of Java. I might be able to target the Java VM, but I’m not sure yet. In any case it’s a good chance to brush up my Java and learn IntelliJ IDEA (CE). I’m using SableCC to parse, and I’ve just got Log4j working. I’m long overdue writing some unit tests but for the moment, after a week or so, I have a working interpreter and the following sample script that runs as advertised:

Apart from the env directive, and the fact that strings are lists of chars, this is still very much a scheme interpreter with a more syntax laden parser in front of it, but it’s early days. Next steps:

  • Get unit tests in place. I’ve delayed too long.
  • Implement an implicit strong type-checking visitor (I’m falling out of love with the Visitor pattern, but SableCC gives me no choice.)
  • Replace the variable implementation with the same logic variables used by the type checker.
  • Add algebraic data types a la ML. This should look like:

    (except that List is already predefined.) t is a type variable, so this says List of some type t is either a Pair of a t and a List of t, or it is Null. Pair and Null become type constructors for type List(t), so Pair('c', Null) creates a list of length 1 with type List(char). Like I said, we already have lists, and h @ t is (cons h t), e.g. Pair(h, t).
  • Extend the function definition to allow pattern matching (actually unification). This would look like:

    so the formal arguments to the function can optionally be moved inside the function body, and repeated with alternative formats, like a case statement. The format that unifies with the actual arguments has its body evaluated with the relevant variables bound.
  • Rewrite to CPS, add failure continuations, implement amb as a binary operator then:
  • Implement fail as a keyword of no arguments:

    (That last one might give the type checker a headache.)

 

Leave a Reply

Your email address will not be published. Required fields are marked *