cdiggins.com

January 26, 2008

UML: Data-types vs Classes

Filed under: Everything — cdiggins @ 7:38 am

I am studying UML right now, and I am grappling with a pretty fundamental question: why not always use classes instead of domain specific data-types? Is it just to make the diagrams prettier. Please email me with your thoughts.

January 22, 2008

Programmer Defined Verification of Keyword Semantics using Annotations

Filed under: Everything — cdiggins @ 1:05 am

The following is from a recent query I made to the Lambda-the-Ultimate.com community: 

I’m designing a generic object oriented language, and I would like to replace all of those silly declaration modifiers that you often see (e.g. public, protected, private, internal, const, static, etc.) with annotations. My plan is to introduce a preprocess phase, executed immediately after compilation, that allows the program to verify that the semantics associated with the various annotations are respected.

This phase would be simply a call to some “preprocess” function from the compiler, which uses the langauge’s own reflection facilities to allow the programmer to walk the code and verify things. This seems relatively straightforward, but I am concerned that there are well-known pitfalls that in my infinite naivete I may be overlooking. There is of course the really obvious stuff like the possibility of a non-terminating or intractably complex algorithm at compile-time, but that I can live with. Thanks in advance for your suggestions.

January 15, 2008

The Type of an Empty List

Filed under: Everything — cdiggins @ 9:04 pm

So I started adding typed lists to Cat by representing them as functions that push two values on the stack. A value, and the rest of the list. Doing this meant that I could reuse the machinery for typing functions to provide statically typed homogeneous lists. So the cons function for adding a value to a list would have the following type:

cons : (( -> ‘B ’a) ’a -> ( -> ‘B ‘a))

This means that I can simply write:

[1] 2 cons

Which would mean the same thing as

[1 2]

To make the type more manageable I am considering the shorthand notation of [’a] to represent a list of elements of type ‘a:

  cons : ([’a] ‘a -> [’a])

Extracting elements is simply the reverse:

  uncons : ([’a] -> [’a] ‘a)

Okay, hopefully so far that makes a certain amount of sense. Now the problem comes when I have to deal with the empty list. Consider the following:

  [] 1 cons

It is only natural for a programmer to expect this to work, but it won’t type-check! The problem is that [] doesn’t conform to the expected type ( -> ‘B ‘a). This states clearly that something has to be pushed onto the stack. Effectively I need a specialized empty list for every type of list we could have. Now that is kind of what we expect in a Java like language: you construct empty lists by explicitly calling the correct constructor (e.g. new List<Whatever>()). It is just a bit frustrating because programmers used to dynamic languages like Scheme are going to expect a single empty list constructor that works for anything (e.g. ‘()).

So what is a language designer to do? One option is to overload “cons” so that it is actually two functions. One that takes an untyped empty list of any type and returns a new typed unit list, and the other takes a typed list of a specific type. This is the best option I can come up with, but it requires a new language feature: multimethods. In other words I would need Cat to perform dynamic dispatching of functions based not only on names, but on the types of the items on the list.

The other option is to require a special empty list constructor that takes a type as a parameter. For example:

  int list new

Which would have the type: ( -> [int]).

This would require a slightly smaller overhaul of the language. I just need to be able to construct types dynamically. I can live with that.

I’d love to hear your thoughts on the Cat mailing list.

January 13, 2008

What to expect for Cat 0.19

Filed under: Everything — cdiggins @ 6:17 pm

I am currently working hard on the next release of Cat. This release will include a major clean-up of the code. It has evolved into a nasty mess, and I want to make sure that it is easy to reuse Cat more easily in other C# projects. I am abandoning the IDE features I started adding, since it was simply too ambitious. I put a fair amount of effort into developing an efficient syntax coloring API using RTF, so at some point I’ll try to post an article contiaining that code at CodeProject.com.

If all goes according to plan we will be seeing the following features in the next version:

  • nested defines
  • reflection API
  • external API definitions
  • tail call optmization
  • dynamic stack sizing
  • call with current continuation
  • typed lists

A big thank you to Chris Rathman for identifying several short-comings of Cat through his SICP translation project.

January 9, 2008

A Scheme to Cat Compiler

Filed under: Everything — cdiggins @ 4:09 pm

I’ve written a simple compiler from Scheme to Cat in Scheme for a course and posted it, along with an extremely rushed technical report, at: http://www.cat-language.com/s2cat.zip. Unfortunately it only works on Gambit Scheme. I tried making it R5 compliant, but I couldn’t figure out how long it would take. I felt like I was programming Pascal on Dos, because I would only get one error message at a time! I hope someone will care enough to make it R5 complaint and share it back with the community.

Anyway, in summary the compiler is relatively simple, and the only thing a little out of the ordinary is the optimizer, which is a partial evaluator based on rewriting rules.

January 4, 2008

Progress on Scheme to Cat

Filed under: Everything — cdiggins @ 2:31 pm

I have been spending the last few weeks working on a Scheme to Cat compiler written in Scheme. It is partly for a school project on compilers, but the hidden agenda was to demonstrate that compiling to Cat was feasible. What appears to be novel about this compiler is that I use a partial-evaluator to manage combinatory explosion. There were some interesting technical challenges which are going to lead to some new features in the Cat language.

Briefly the features to watch for in the next Cat release are:

- Cat is going to become properly tail-recursive. This means basically that any recursive calls in tail-position (e.g. the last call in an expression) will not cause stack growth.

- Cat will have call-with-current-continuation. This means that a copy of the stack can be made.

- Cat will allow mutable shared data values. This allows commands like “set!” in Scheme which changes a variable.

Other than that no other changes to Cat are needed to make the translation from Scheme to Cat work properly.

Powered by WordPress