Function types in ALFE

This is part of the ALFE types series.

Foo(Bar) is a function type - the type of a function taking Bar and returning Foo. It is syntactic sugar for Function<Foo, Bar>. Similarly, the zero-argument function type Foo() is short for Function<Foo> and the two-argument function Foo(Bar, Baz) is short for Function<Foo, Bar, Baz> so Function is a variadic template, a curious kind of type constructor which I'll talk more about in a future post.

A function type is a bit unusual in that it is not of definite size, so you can't declare a variable of this type on the stack or as a member of another type (the syntax for doing so would be too similar to declaring an actual local function or method instead). However, pointers to functions like Foo()* work fine, just as they do in C and C++ (albeit with an easier to understand syntax). Function types can also be used as template arguments. Raw function types might also come in handy for run-time code generation, but I haven't yet finalized the syntax for that.

Bar -> Foo is yet another way of writing Foo(Bar). I'm not sure if there's much of advantage to having this syntax as well as the other, but there might be some circumstances in which it makes more sense.

One Response to “Function types in ALFE”

  1. [...] Some of the types in ALFE are templates which can accept different numbers of parameters - in other words, variadic templates. How does this fit in with the Kind system I wrote about before? [...]

Leave a Reply