Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Type inference woes

Name: Anonymous 2019-01-25 15:56

CONSIDER this Rust code that a reasonable human being might try to write:

fn add<T>(a: T, b: T) -> T {
return a + b;
}

If you try to compile that, you’ll get an error like this:

:1:25: 1:30 error: binary operation `+` cannot be applied to type `T`
What you actually have to write is something like this:

use std::ops::Add;
fn add<T: Add>(a: T, b: T) -> T::Output {
return a + b;
}

Now it typechecks correctly.

This seems a little ridiculous. The compiler already knew that T had to be a type that supports addition — it just told me that. So why am I spelling it out?

Name: Anonymous 2019-01-28 10:28

LISP 1.5 Update :
Dear Lisp users, we're introducing a
revolutionary concept, Numbers.
Numbers are faster than Church numerals(currently represented as lists of atoms) by several orders of magnitude.
They also require much less memory to store, so you can run bigger programs.
You can now enjoy new vast options of using complex math functions such as sqrt, fact and fibs.
--John McCarthy

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List