brendanzab / algebra

Abstract algebra for Rust (still very much a WIP!)
Apache License 2.0
60 stars 9 forks source link

Algebra and unsafe #27

Open WaDelma opened 8 years ago

WaDelma commented 8 years ago

If somebody wants to make use of algebraic properties in unsafe code, they cannot trust normal traits.
Should there be some kind of unsafe marker trait that is needed for unsafe to trust algebraic traits? Something like: unsafe trait CorrectAlgebra {}

WaDelma commented 8 years ago

Other choice is to have same kind of thing as the Approx* variants, but that creates lots of bloat.

However it has the benefit of being more flexible: If the unsafe just needs the one algebraic property to be safe, it can be encoded.

milibopp commented 8 years ago

I really don't know… This does not actually provide any type safety, it's more like waving a red flag: “Hey, you might potentially mess up memory management by using this!”

Rust is missing dependent types for this to be actually useful. And in the current situation I'm not sure whether I would really use this for encoding semantics that are not inherently memory-unsafe. After all, would you really rely on such properties of an abstraction when implementing unsafe code? This isn't going to make it any safer.

WaDelma commented 8 years ago

Well the whole unsafe keyword is basically just waving red flag too so I don't see big difference with this vs it.

I do agree that dependent types would make it more useful, but still it's better than nothing?

And yeah I don't really have good use case for this yet.

milibopp commented 8 years ago

Sure, but you are mostly asserting the memory-safety of whatever you are doing inside. I find it somewhat confusing to use the keyword to convey other semantics, that can't be strictly enforced at compile-time. I guess, it's a trade-off?

But yeah, a use case would certainly be a nice example to drive this discussion. Comparing what it looks like and how the old behaviour might surprise a user, where adding an unsafe trait like that would help.

brendanzab commented 8 years ago

Hey @WaDelma, would you be interested in taking over this library? I don't currently have a great deal of time to spend on it, and you seem interested in pushing it forwards - which is great!

WaDelma commented 8 years ago

Well I would be interested if I had stronger knowledge on algebra... I really would like this to be thing that can be used, but I don't know if I can make it work.