GankroOPrust•

As of... like an hour ago (shhh)... I start my job at Apple. Everything I produce related to computers/programming now needs to feed through Apple's legal department to see the outside world. So this isn't particularly well edited or reviewed. It's just something I wanted to write down, and figured other people might find useful. Had to knock it out before The Apple Blackhole kicked in.

This is actually basically a massive self-nerd-snipe. Sometime earlier this week I decided to write an RFC issue (not even an RFC!) to the effect of "support generativity as a first class notion". I started to write out why generativity was useful, which led me to start to write a brief comparison of why generics/assoc-items/hrtbs exist, which then led me to backfill and forward fill context, until I awoke several days later to a 9000 word abomination.

Along the way I pinged Niko and Aaron like a billion times to argue what was or wasn't expressible and "what even is a higher kinded type even". I also found a bug in the compiler, because that's what happens when you abuse the type-system.

48
pjmlp•

Congratulations!

Now more Swift and less Rust, or is Apple going to do Rust related stuff?

Assuming you can answer about it, that is.

17
GankroOPrust•

I sure can't answer about this.

All I can say is I'm on Apple's Special Projects Group, on the Dev Tools Team with a focus on programming language research and development.

My official stance is that I develop GUIs for Visual Basic.

34
nuggins•

My official stance is that I develop GUIs for Visual Basic.

Wow, I didn't know Apple has a forensics department!

14
GankroOPrust•

No, that would be developing a GUI in Visual Basic. I'm doing real reasearch.

13
Manishearthrust · servo · clippy•

Special Projects Group

That sounds like some top secret government lab from a superhero movie.

Watch out for radioactive spiders. Or actively seek them, if that's what floats your boat.

6
ben0x539•

must be a pretty rad job when it's worth giving up so much, congrats~

3
pjmlp•

:)

1
GankroOPrust•

One thing I didn't get time to really consider was this alternative encoding of RefIterator that ajeffery proposed at like 11pm: https://play.rust-lang.org/?gist=a4804463ed645130b227&version=stable

I feel like unifying all those lifetimes must surely do something dumb to the borrow checker, but I'm not certain how to trip it.

12
asajeffrey•

Sorry about that! The coding works in a lot of cases, but it's probably not infallible, for the same reason that you can express a lot of higher type classes without HKT, but not everything. For example, you can express that a type has a map method, you just can't express that it returns an instance of the same type function. I'm not sure this matters so much for iterators, where you care about the type of the items, not the type of the iterator.

1
jarxlots•

As of... like an hour ago (shhh)... I start my job at Apple. Everything I produce related to computers/programming now needs to feed through Apple's legal department to see the outside world. So this isn't particularly well edited or reviewed. It's just something I wanted to write down, and figured other people might find useful. Had to knock it out before The Apple Blackhole kicked in.

Congrats, but I would recommend being under an NDA that you have "vicarious control" over before signing the Apple NDA. That way you can decide what qualifies for Apple's NDA without their interference.

7
yuriks•

I'm sorry for your loss. :)

1
ksion•

This guy is doing C++ template metaprogramming in Rust. Stop him! Stop him before it's too late!

10
diwic•

Congrats!

impl <Gymnosporangium juniperi-virginianae> for Gankro

And what an essay :-)

7
neutralinostaritertools · rust•

Here's a cool code reuse pattern that we put into libcore to be able to support two cases in the string searcher: 1) Fastest scan to next match and 2) Next reject or match result.

It uses a type parameter and a strategy trait to use the same code for the two strategies. Usage site. Strategy definition.

5
GolDDranks•

// Inserting a u8 into the x solidifies its type to Vec<T>

I bet you meant to say: solidifies its type to Vec<u8>?

Also: congrats on your new job! But does that mean that you can't properly participate in the Rust community anymore?

5
diwic•

I found a typo!

for<'a> F: Fn(&I::Item) -> bool

You probably mean:

for<'a> F: Fn(&'a I::Item) -> bool
4
gnzlbg•

That "bugfix" would belong to Apple now.

2
nawfel_bgh•

Rust 1.7 isn't stable yet!

3
GankroOPrust•

It is in my heart.

15
arielby•

The annoying part of coherence is not the overlap rules, but the future-compatibility orphan rules (https://github.com/rust-lang/rfcs/blob/master/text/1023-rebalancing-coherence.md) , which attempt oh-so-helpfully to prevent you from writing an impl that could possibly be invalidated when std changes.

3
GankroOPrust•

There is more than one reason why I hand waived all this away :)

1
Sgeo•

This means that a Clone trait object is actually nonsensical. More generally, any trait that talks about Self by-value anywhere can't be turned into a trait object.

I'd imagine even talking about Self by reference anywhere other than the first argument would also be a problem, because it is nonsensical to talk about returning a &Self that you don't know what it is, for example. I haven't checked, though.

2
diwic•

What would be useful to have though is a BoxClone trait which would return a Box<Self>. That shouldn't pose any problems in theory, because Box<Self> where self is a trait is always the size of a pointer.

But I don't know any way to make this happen in Rust. :-(

5
GankroOPrust•

Ah, yep! Good call.

2
gnzlbg•

First, THANKS!

Second:

I should probably explain the orphan rules properly.

Are they explained somewhere in the book?

Syntax extensions look like macros or annotations, but they cause the compiler to execute custom code to (ideally) modify the AST. build.rs files are a file that Cargo will compile and execute whenever a crate is built.

And these?

2
willi_kappler•

Syntax extensions: For ex. here and here.

build.rs is described here.

2
nawfel_bgh•
trait RefIterator {
	type Item;
	fn next(&mut self) -> &mut T // `T` should be `Self::Item`
}

Those Apple reviewers are no good!

2
nawfel_bgh•

This example:

fn main() {
	let x: Box<Print> = Box::new(0u32);
	x.print();
}

will be clearer if you add x.copy(); // generates a compiler error

1
willi_kappler•

A big "thank you" for researching and writing this! And all the best for your new job ;-)

1
h3st•

Some common examples of monomorphization:

What, no mention of {-# LANG NoMonomorphismRestriction #-}? :~) I'm sure there are other haskellers who twitched at reading the monomorphism header.

1
dbaupprust•

Monomorphism and monomorphisation are slightly different. The former affects when things are generic, while the latter is a strategy for compiling/generating code for generic code.

1
brokenAmmonite•

This is great! One note:

Inserting a u8 into the x solidifies its type to Vec<T>

Should read:

Inserting a u8 into the x solidifies its type to Vec<u8>

1
PM_ME_UR_OBSIDIAN•

Macros are the easiest.

[citation needed]

Also, A Brief Review of Code Reuse is missing codatatypes - Java and C#'s interfaces, Haskell and Scala's typeclasses, and arguably Rust's traits. Also intersection types, which tie into traits.

1
GankroOPrust•

The point is that they're all ultimately just expressing "monomorph, virtualize, or enumerate". Everything on top is just providing different knobs on the process.

3