Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Oct 18 19:35
    @SethTisue banned @lunaterra22
  • Sep 14 18:08
    @SethTisue banned @discjock:matrix.org
  • Sep 12 20:37
    @SethTisue banned @manuelzamoratetherbtcusa:matrix.org
  • Sep 06 14:29
    @SethTisue banned @white_hat_hacker:minds.com
  • Sep 06 14:29
    @SethTisue banned @alexchole:matrix.org
  • Aug 31 17:03
    @SethTisue banned @andersonwatts7:matrix.org
  • Jul 19 20:37
    @SethTisue banned @tonyobanon
  • Jan 02 23:58
    @SethTisue banned @fakubishes:nerdsin.space
  • Dec 15 2021 05:01
    som-snytt commented #12516
  • Dec 15 2021 04:38
    SethTisue edited #1312
  • Dec 15 2021 04:38
    SethTisue opened #2273
  • Dec 15 2021 04:31
    jackkoenig opened #12516
  • Dec 15 2021 04:29
    SethTisue edited #1312
  • Dec 15 2021 04:28
    SethTisue edited #1312
  • Dec 15 2021 04:27
    SethTisue labeled #9831
  • Dec 15 2021 04:27
    scala-jenkins milestoned #9831
  • Dec 15 2021 04:27
    SethTisue labeled #9831
  • Dec 15 2021 04:27
    SethTisue opened #9831
  • Dec 15 2021 03:35
    som-snytt commented #11339
  • Dec 15 2021 03:27
    som-snytt labeled #12494
Ichoran
@Ichoran
@klassegeljakt - No, it's determined within the same expression (with some extra rules about how long types can stay unknown).
Klas Segeljakt
@segeljakt
ok
OlegYch
@OlegYch
variables are uncommon in scala
Klas Segeljakt
@segeljakt
maybe that is the difference, in Rust you can do
let x = 3.3;
let y: f32 = x;
let z: f64 = x; // ERROR x is of type f32
I think
Rob Norris
@tpolecat
Well you can do that in Scala if f32 and f64 both conform with the inferred type of x.
But the type of x is inferred before it ever looks at y.
Klas Segeljakt
@segeljakt
ok
Rob Norris
@tpolecat
Inference in Scala is primitive, and not only due to limitations of the formalism (such as it is).
OlegYch
@OlegYch
pretty sure let y is of no consequence there
Rob Norris
@tpolecat
It's designed to hit the common cases relatively efficiently.
Klas Segeljakt
@segeljakt
let x = 3.3;
let y: f64 = x;
let z: f32 = x; // ERROR x is of type f64
OlegYch
@OlegYch
hm
Ichoran
@Ichoran
It's different in Scala.
Klas Segeljakt
@segeljakt
I can test
does the Scala inference algorithm have a name?
or is it specific to Scala
Rob Norris
@tpolecat
It's an implementation detail. It's not specified.
Ichoran
@Ichoran
val x = 1    // now x has type Int
val y: Short = x   // fails
val z: Long = x  // succeeds
And it works that way because of numeric widening.
Otherwise it would fail both lines.
Rob Norris
@tpolecat
Numeric types confuse the discussion I think because you have to think about weak conformance.
Ichoran
@Ichoran
Another case of the locality of type inference occurs with cases like def foo[A, B](a: A)(b: B, f: A => B) = ...
Ghost
@ghost~54f4b69115522ed4b3dcb16d
@mpasa with two X, you get a female option, but with a Y you get a male. There's a general sense that Y is more expendable; also, you can't rely on a Y when you need it. Sometimes a Y will transition to an X, and suddenly becomes pleasant to work with.
Ichoran
@Ichoran
Here, once you get past a: A, the compiler has decided what A is supposed to be. It can't use the stuff in f: A => B to help it decide.
Derek Wickern
@dwickern
so rust decides on the type of x the first time it's used?
Ichoran
@Ichoran
On the one hand that's bad, because you have to manually widen types. On the other hand, it's good because you can nail down your function types based on earlier arguments.
I think bad outweighs good, but it's not all purely bad :P
Klas Segeljakt
@segeljakt
yea it appears so
Ichoran
@Ichoran
Rust decides on the type of x the first time it is unambiguous what the type is.
It's not just when it's used. It can propagate "Hey, I don't know what type this is" for rather a while.
Harrison Houghton
@hrhino
@som-snytt what about in those rare and unfortunate cases where you get an XXY option?
OlegYch
@OlegYch
i'd guess it is necessary to support borrow checker and inference
Derek Wickern
@dwickern
it seems like that could get very confusing
do people abuse it?
Rob Norris
@tpolecat
Sounds like a kind of gruadual typing.
OlegYch
@OlegYch
linear
Rob Norris
@tpolecat
Well there's that too.
Klas Segeljakt
@segeljakt
what is linear typing?
Rob Norris
@tpolecat
I mean constraining a variable's type based on how it's used.
Miguel Pérez Pasalodos
@mpasa
@som-snytt thanks!
Ichoran
@Ichoran
For example, Rust is totally okay with this, and it's not because the 0 is naturally typed as u64:
fn main() {
    let a = 0;
    let mut b = a + a;
    let c = a + b;
    b += c;
    let d: u64 = c*b;
    println!("d is {}", d);   // Compile error
}
In contrast, with Scala, once you do val a = 0 it fixes the type as Int. If you want it to be something else, you have to say so there.
Klas Segeljakt
@segeljakt
I thought it had affine types
Ichoran
@Ichoran
Yeah, it has, actually, something a little bit more complicated than either affine or linear types.
But it's the same essence.
Klas Segeljakt
@segeljakt
ownership + move = affine?
but then you also have copy
and borrow
Ichoran
@Ichoran
It's affine-like, but there's the whole single-mutable-borrow-or-arbitrary-immutable-borrow thing.