lloydmeta / frunk

Funktional generic type-level programming in Rust: HList, Coproduct, Generic, LabelledGeneric, Validated, Monoid and friends.
https://beachape.com/frunk/
MIT License
1.29k stars 58 forks source link

CNil::absurd() for producing any type #93

Closed ExpHP closed 6 years ago

ExpHP commented 6 years ago

Dangit, I'm having too many ideas all at once now!

impl CNil {
    pub fn absurd<T>(self) -> T {
        match self { }
    }
}

Bikeshedding for the name is welcome. The name absurd() comes from proof solvers. Picture it appearing e.g. at the bottom of this example, or as the body of this impl. (random aside: uh... why is that impl #[doc(hidden)]?)

Centril commented 6 years ago

Hmm; Rather than doing this (and since we introduced some other breaking changes in master), I'd like us to get rid of CNil and simply use ! (assuming we can do it wrt. coherence, which I think we can), this is what the standard library has been doing as of late, and the hope is that ! should be the only uninhabited type in the entire ecosystem.

I'd personally like to have:

#[lang_item = "never"]
impl ! {
    pub fn absurd<T>(self) -> T {
        match self {}
    }
}

in the standard library tho.

ExpHP commented 6 years ago

Okay. Do note that this will prevent inherent method wrappers (#90) on empty coproducts. That said, in most cases not having these methods is not a huge loss (most have no implementations for CNil, and who needs to take a subset() of a coproduct that is monomorphically known to be empty?); rather, it's just one of those places where the ergonomic hack will become a leaky abstraction.

(for instance, it could be an issue for code generated by macros)

Centril commented 6 years ago

Okay. Do note that this will prevent inherent method wrappers (#90) on empty coproducts. That said, in most cases not having these methods is not a huge loss [..]

Yeah sounds fine ^,-

ExpHP commented 6 years ago

Do you mean that not having the wrappers on CNil sounds fine? Or that keeping CNil around sounds fine?

Centril commented 6 years ago

Sorry, I meant the former.

ExpHP commented 6 years ago

Okay, I'll close this for now.