by jaseemabid on 10/12/19, 9:52 PM with 183 comments
by foopdoopfoop on 10/12/19, 11:42 PM
`Inductive False := .`
i.e., `False` has no constructors and hence is an empty type.
Anyway, this means that for any type `A`, you can construct a function of type `False -> A` because you just do this:
`fun (x : False) => match x with end.`
Since `False` has no constructors, a match statement on a value of type `False` has no cases to match on, and you're done. (Coq's type system requires a case for each constructor of the type of the thing being matched on.) This is why, if you assume something that is false, you can prove anything. :)
by unexaminedlife on 10/13/19, 1:07 AM
Isn't it really only there in case someone needs to "hook into" the drop functionality before the variable is dropped? Please correct me if I'm wrong.
EDIT: Minor editing to clarify meaning.
by holy_city on 10/13/19, 12:07 AM
One cool thing about Drop (and some other cool stuff, like MaybeUninit) is that it makes doing things like allocating/freeing in place just like any other Rust code. There may be some unsafe involved, but the syntax is consistent. Whereas in C++ seeing placement new and manually called destructors can raise eyebrows.
by dbieber on 10/12/19, 11:36 PM
If I do the rust equivalent of:
def add1(x):
return x + 1
x = 1
y = add1(x)
z = add1(x)
then will x have been deallocated by the first call to add1 and will the second call to add1 fail?[You can ignore the fact that I'm using numbers and substitute an object if that makes more sense in the context of allocating / deallocating memory in rust.]
by grenoire on 10/12/19, 10:33 PM
by lpghatguy on 10/13/19, 2:29 AM
|_| ()
[1] https://twitter.com/myrrlyn/status/1156577337204465664by hinkley on 10/12/19, 11:44 PM
In which case there’s only one situation where I could see this useful, and that’s when you are building a large object to replace an old one.
The semantics of
foo = buildGiantBoject();
In most languages is that foo exists until reassigned. When the object represents a nontrivial amount of memory, and you don’t have fallback behavior that keeps the old data, then you might see something like drop(foo);
foo = buildGiantBoject();
Most of the rest of the time it’s not worth the hassle.by saagarjha on 10/12/19, 10:38 PM
by newacctjhro on 10/13/19, 1:54 AM
The compiler actually implicitly adds drop glue to all dropped variables!
by cztomsik on 10/13/19, 12:05 AM
It's a wonderful language but there are still some PITAs. For example you can't initialize some const x: SomeStruct with a function call. Also, zero-cost abstraction is likely the biggest bullshit I've ever heard, there is a lot of cost and there's also a lot of waiting for compiler if you're using cargo packages.
That said, I wouldn't rather use C/C++/Go/Reason/Ocaml/? - that is probably the love part.
BTW: I've recently stopped worrying about unsafe and it got a bit better.
So my message is probably: - keep your deps shallow, don't be afraid to implement something yourself - if you get pissed off, try again later (sometimes try it the rust way, sometimes just do it in an entirely different way)
by millstone on 10/13/19, 1:09 AM
let x = String::from("abc");
std::mem::drop(&x);
std::mem::drop(&x);
std::mem::drop(&x);
std::mem::drop(&x);
by flywithdolp on 10/13/19, 7:01 AM
The beauty of programming language design is not building the most complex edifice like Scala or making the language unacceptably crippled like Go - but giving the programmer the ability to represent complex ideas elegantly and safely. Rust really shines in that regard.
i'm fairly ignorant on the various differences but my general feeling was that Go is quite useful?
by gautamcgoel on 10/12/19, 11:40 PM
by jchw on 10/12/19, 11:43 PM
Gotta say, I lost a lot of respect for the author at this point. It’s not like I don’t love Rust - quite the contrary - but if the only takeaway from Go for you is that it is “unacceptably crippled” then I feel you have missed a lot of insight. Go has been one of my languages of choice for over half a decade now, and for good reason.
by etxm on 10/12/19, 11:29 PM
I just spit mezcal on a stranger.