{"id":1836,"date":"2012-10-14T20:00:48","date_gmt":"2012-10-14T19:00:48","guid":{"rendered":"https:\/\/www.reenigne.org\/blog\/?p=1836"},"modified":"2012-09-23T09:17:27","modified_gmt":"2012-09-23T08:17:27","slug":"function-types-in-alfe","status":"publish","type":"post","link":"https:\/\/www.reenigne.org\/blog\/function-types-in-alfe\/","title":{"rendered":"Function types in ALFE"},"content":{"rendered":"<p>This is part of the <a href=\"https:\/\/www.reenigne.org\/blog\/the-alfe-type-system\">ALFE types series<\/a>.<\/p>\n<p><strong>Foo(Bar)<\/strong> is a function type - the type of a function taking <strong>Bar<\/strong> and returning <strong>Foo<\/strong>. It is syntactic sugar for <strong>Function&lt;Foo, Bar&gt;<\/strong>. Similarly, the zero-argument function type <strong>Foo()<\/strong> is short for <strong>Function&lt;Foo&gt;<\/strong> and the two-argument function <strong>Foo(Bar, Baz)<\/strong> is short for <strong>Function&lt;Foo, Bar, Baz&gt;<\/strong> so <strong>Function<\/strong> is a variadic template, a curious kind of type constructor which I'll talk more about in a future post.<\/p>\n<p>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 <strong>Foo()*<\/strong> work fine, just as they do in C and C++ (albeit with an <a href=\"https:\/\/www.reenigne.org\/blog\/cases\">easier to understand syntax<\/a>). Function types can also be used as template arguments. Raw function types might also come in handy for <a href=\"https:\/\/www.reenigne.org\/blog\/compiler-compilers\">run-time code generation<\/a>, but I haven't yet finalized the syntax for that.<\/p>\n<p><strong>Bar -> Foo<\/strong> is yet another way of writing <strong>Foo(Bar)<\/strong>. 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.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&lt;Foo, Bar&gt;. Similarly, the zero-argument function type Foo() is short for Function&lt;Foo&gt; and the two-argument function Foo(Bar, Baz) is short for Function&lt;Foo, Bar, Baz&gt; so Function [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,27],"tags":[],"class_list":["post-1836","post","type-post","status-publish","format-standard","hentry","category-computer","category-language"],"_links":{"self":[{"href":"https:\/\/www.reenigne.org\/blog\/wp-json\/wp\/v2\/posts\/1836","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.reenigne.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.reenigne.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.reenigne.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.reenigne.org\/blog\/wp-json\/wp\/v2\/comments?post=1836"}],"version-history":[{"count":5,"href":"https:\/\/www.reenigne.org\/blog\/wp-json\/wp\/v2\/posts\/1836\/revisions"}],"predecessor-version":[{"id":1900,"href":"https:\/\/www.reenigne.org\/blog\/wp-json\/wp\/v2\/posts\/1836\/revisions\/1900"}],"wp:attachment":[{"href":"https:\/\/www.reenigne.org\/blog\/wp-json\/wp\/v2\/media?parent=1836"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.reenigne.org\/blog\/wp-json\/wp\/v2\/categories?post=1836"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.reenigne.org\/blog\/wp-json\/wp\/v2\/tags?post=1836"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}