Evan Martin (evan) wrote in evan_tech,
Evan Martin

More fun hackin' on my language lately. It's gonna be C-level with a more ML/Haskell-ish syntax and with a fancier type system.

One of my main thoughts recently is that one use of a type system is to enforce conventions. With conventions built into the type system, I can make the associated syntax overhead lighter. For example, good C libraries conventionally namespace their code by using prefixes, so I can provide a "namespace { ... }" construct that does this automatically. A more involved convention is Glib's error reporting, which as you can think of as the natural way to do exceptions in C without using setjmp hacks. Rather than the convention of having every exception-raising function take in an extra GError**, I can provide an "exception" tag on function declarations and provide the corresponding raise, try, catch (rescue? with?) functionality myself.

Recent gotcha: if you allow type constructors, than code like
char foo(int x, int y)
(which looks like a function declaration and requires an opening curly to its right) is ambiguous. Just changing the names of the identifiers, to make it more clear:
option hash(list string, list int)
which looks like a complicated type (in OCaml syntax: (string list, int list) Hashtable.t option¹). The parser doesn't expect a opening curly to follow it.

Recently working on / thinking about: any type that's of pointer kind can have a "maybe" attribute, which corresponds to the possibility of being NULL in C. A string (which is a char*, so that's a pointer kind) is a subtype of {maybe}string, so you can pass variables of the former form to functions expecting the latter, but not the reverse—you have to test for NULL first.

1 Again, it's the backwards problem: I write ref int in OCaml to get something of type int ref.
# Some 3;;
- : int option = Some 3

Haskell (who got it right, I think):
Prelude> :type Just 3
Just 3 :: Num a => Maybe a

  • memcache job offers

    I get occasional recruiter spam that specifically calls out "my work on memcached". This is pretty funny because all I did was make some trivial…

  • application stack

    "Put yourself in 1995. I'm going to tell the you of 1995 that in 2010, there will be a software platform with the following properties:" Luis Villa…

  • bsd license advertising

    Did you know that the 3-clause BSD (that is, the one with the "advertising" clause stripped) license still has an advertising requirement? Read it…

  • Post a new comment


    default userpic
    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.