Ali Çehreli:

Ali Çehreli's (first speaker) slides are at

  http://acehreli.org/AliCehreli_assumptions.pdf

It's a nice slides pack. Now in Phobos there's also assumeUTF (https://d.puremagic.com/issues/show_bug.cgi?id=10162 ).

See also:
https://issues.dlang.org/show_bug.cgi?id=9682

It essentially asks two functions (group and filter) to return a SortedRange if the input is a SortedRange, because those two functions don't change the items order.

In Haskell you do such things using "rewrite rules" (https://www.haskell.org/ghc/docs/7.0.1/html/users_guide/rewrite-rules.html ).

Those are two examples of conservation of assumptions (invariants).

assumeUnique returns an immutable instead of a Unique!T struct. So after calling assumeUnique you can't mutate the items. An Unique!T wrapper (like std.typecons.Unique) allows you to mutate the items if the needs arises but also to keep their property of having no shared references. Some functions like sort() are able to conserve the property of uniqueness, so sorting an array of Unique should return a SortedRange!(Unique!T[]) or something like that.

Another assumption that could be useful for Phobos is assumeAligned!(T[], 16), that specifies the assumption that a specific slice has its first item aligned to 16 bytes. This could be useful if you use SIMD instructions (time ago I have even suggested to put such array alignment inside the D type system, but I didn't raise much enthusiasm).

Bye,
bearophile

Reply via email to