<feed xmlns='http://www.w3.org/2005/Atom'>
<title>slang.git/tests/compute/this-type.slang.expected.txt, branch master</title>
<subtitle>Making it easier to work with shaders</subtitle>
<id>https://git.yummers.dev/slang.git/atom?h=master</id>
<link rel='self' href='https://git.yummers.dev/slang.git/atom?h=master'/>
<link rel='alternate' type='text/html' href='https://git.yummers.dev/slang.git/'/>
<updated>2020-02-21T18:39:05+00:00</updated>
<entry>
<title>Add surface syntax for "this type" (#1236)</title>
<updated>2020-02-21T18:39:05+00:00</updated>
<author>
<name>Tim Foley</name>
<email>tfoleyNV@users.noreply.github.com</email>
</author>
<published>2020-02-21T18:39:05+00:00</published>
<link rel='alternate' type='text/html' href='https://git.yummers.dev/slang.git/commit/?id=830671c2210191f69ddc403cc12f5454bb55b0f0'/>
<id>urn:sha1:830671c2210191f69ddc403cc12f5454bb55b0f0</id>
<content type='text'>
Within the context of an aggregate type (or an `extension` of one), the programmer can use `this` to refer to the "current" instance of the surrounding type, but there is no easy way to utter the name of the type itself. This is especially relevant inside of an `interface`, where the type of `this` isn't actually the `interface` type, but rather a placeholder for the as-yet-unknown concrete type that will implement the interface.

This change adds a keyword `This` that works similarly to `this`, but names the current *type* instead of the current instance. It can be used to declare things like binary methods or factory functions in an interface:

```
interface IBasicMathType
{
    This absoluteValue();
    This sumWith(This left);
}

T doSomeMath&lt;T:IBasicMathType&gt;(T value)
{
    return value.sumWith(value.absoluteValue());
}
```

The `This` type is consistent with the type named `Self` in Rust and Swift (where Rust/Swift use `self` instead of `this`). Other names could be considered (e.g., `ThisType`) if we find that users don't like the name in this change.</content>
</entry>
</feed>
