• Murdo Maclachlan@lemmy.world
    link
    fedilink
    arrow-up
    18
    ·
    8 months ago

    Image Transcription:


    type Wtf = Option>>>>>>>;
    let two = Some(Some(Some(Some(Some(Some(None))))));
    let three = Some(Some(Some(Some(Some(None)))));
    let six = Some(Some(None));
    unsafe {
        assert_eq!(
            std::mem::transmute::(two) * std::mem::transmute::(three)
            std::mem::transmute::(six)
        );
    }
    

    I am a human who transcribes posts to improve accessibility on Lemmy. Transcriptions help people who use screen readers or other assistive technology to use the site. For more information, see here.

  • jeffhykin@lemm.ee
    link
    fedilink
    arrow-up
    16
    ·
    edit-2
    8 months ago

    If you think that’s bad take a look at this real code posted as a real issue on one of my Github repos, which was described as quite short

    • parlaptie@feddit.de
      link
      fedilink
      arrow-up
      3
      ·
      edit-2
      8 months ago

      That’s not actual code though, it looks like some kind of trace. Notice the filenames at the end of each line.

      The actual solution the issue opener there might be looking for is to disable C++ parsing, since it’s not actually C++ code, it’s just some text they pasted into VSCode and they’re wondering why their editor can’t handle it.

  • GissaMittJobb@lemmy.ml
    link
    fedilink
    arrow-up
    7
    ·
    8 months ago

    Since all of the expressions just wrap a None, I wouldn’t be surprised if the transmutes basically get compiled to 0, making the assertion at the end assert_eq!(0 * 0, 0).

    • tatterdemalion@programming.dev
      cake
      OP
      link
      fedilink
      arrow-up
      6
      ·
      edit-2
      8 months ago

      Nah these are the actual integer representations. Otherwise you would have Some(None) == Some(Some(None)) which is way too Javascripty for Rust folks.

    • Knusper@feddit.de
      link
      fedilink
      arrow-up
      1
      ·
      8 months ago

      No, not at all. It’s a joke post, abusing the in-memory representation of the Option type to construct numbers. When nesting the Option type, it turns into a densely packed bit vector…

      And if I understand the purpose of Fin correctly, you’re picking on the one ‘peasant language’ that actually has something like that built-in.
      In Rust, you can specify the type of an array as e.g [u8; 3]. Which is an array containing values of type u8 (unsigned 8-bit integer) with a fixed, compile-time-guaranteed length of 3. So, [u8; 3] could be used to represent an RGB color, for example.
      It is an array, not a set, but well, close enough.

      • baseless_discourse@mander.xyz
        link
        fedilink
        arrow-up
        0
        ·
        edit-2
        8 months ago

        Fin is a type of finite oridinals bounded by a nat. For example the WTF type in there is the same type as Fin 8.

        Of course every language can have Fin with a fixed integer, like the post suggest, by just stacking options.

        However for a properly defined Fin type, the input number is dynamic, serves as a bound for the element of the type. For example, Adga was able to type the fact that nth fibonacci number is a finite ordinal bounded by a function of n. Which I believe is not typable in rust?

  • gsfraley@lemmy.world
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    8 months ago

    For those interested, this is because of how Rust uses value gaps to represent its nullable/enum structures. E.g., like how None for Option NonZeroU8 [sic, can’t get formatting to work] is represented internally by a 0 instead of a wrapping structure.

    When you have that many layers around a unit, it will start at 0 and bump the internal representation for each Some you turn into a None.