61
submitted 1 day ago* (last edited 1 day ago) by little_ferris@programming.dev to c/rust@programming.dev

If we were to create a Rust version of this page for Haskell, what cool programming techniques would you add to it?

you are viewing a single comment's thread
view the rest of the comments
[-] little_ferris@programming.dev 2 points 1 day ago

Yea it's like when we writeSome(2). It's not a function call but a variant of the Option enum.

[-] barsoap@lemm.ee 3 points 23 hours ago

Enum constructors are functions, this typechecks:

fn foo<T>() {
    let f: fn(T) -> Option<T> = Some;
}

I was a bit apprehensive because rust has like a gazillion different function types but here it seems to work like just any other language with a HM type system.

[-] anton@lemmy.blahaj.zone 1 points 1 hour ago

I was a bit apprehensive because rust has like a gazillion different function types but here it seems to work like just any other language with a HM type system.

The fn(T)->R syntax works for functions without associated data, it discards details of the implementation and works like function pointers in C. This allows them to be copy and 'static.

The other function types can have data with them and have more type information at compile time which allows them to be inlined.
These functions each have their own unwritable type that implements the function traits (Fn(T)->R, FnMut(T)->R and FnOnce(T)->R) depending on their enclosed data.

I hope I remembered everything right from this video by Jon Gjengset.

[-] little_ferris@programming.dev 2 points 22 hours ago

Woah. That's quite interesting. I didn't know that.

this post was submitted on 16 Oct 2024
61 points (96.9% liked)

Rust

5876 readers
71 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

!performance@programming.dev

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 1 year ago
MODERATORS