Types as Interfaces
The article explores using wrapper types like Msg and Timestamped in Haskell to annotate data without modifying existing types directly. It discusses challenges in composing annotated types and suggests using typeclasses for solutions. Emphasizes simplifying code for essential variants.
Read original articleThe article discusses the concept of using types as interfaces in Haskell programming. It explores creating wrapper types to add extra fields to existing types without modifying them directly. By introducing wrapper types like Msg and Timestamped, the article demonstrates how to annotate data with additional information while maintaining composability. It also delves into the challenges of composing different annotated types and proposes the use of typeclasses to address such issues. The author suggests drawing inspiration from layered network protocols to design code with meaningful structure. The article concludes by emphasizing the importance of simplifying code by focusing on essential variants and adapting to meet the primary requirements. Overall, it provides insights into leveraging type systems to design flexible and structured code in Haskell programming.
Related
Interface Upgrades in Go (2014)
The article delves into Go's interface upgrades, showcasing their role in encapsulation and decoupling. It emphasizes optimizing performance through wider interface casting, with examples from io and net/http libraries. It warns about complexities and advises cautious usage.
A reckless introduction to Hindley-Milner type inference (2019)
Hindley-Milner type inference balances expressiveness and legibility in programming languages like Elm and Haskell. It enhances correctness by enforcing strict type checking, limiting coding practices for improved type safety.
Ergonomic Self-Referential Types for Rust
Yoshua Wuyts introduces Ergonomic Self-Referential Types for Rust, enhancing self-referential types accessibility. Features include self lifetimes, fixed memory locations, immovable types, and safe self-references initialization. The discussion showcases async {} and Future usage, emphasizing tracking references and potential Rust type system enhancements. Collaboration with Eric Holk is acknowledged for exploring !Move implications.
Evolving Languages Faster with Type Tailoring
Programming languages face limitations in understanding domain-specific aspects like regular expressions, causing errors. "Type Tailoring" proposes teaching type systems new tricks through metaprogramming tools for improved code efficiency and correctness.
Parse, Don't Validate
The article explores type-driven design in programming, emphasizing "Parse, don’t validate" in Haskell. It showcases using types for robust code, avoiding errors, and enhancing input parsing efficiency in various tasks.
type FooBar = Foo & Bar
I doubt you will find a language where it is less clunky.Edit: Oh, I typed this on mobile, this was supposed to be a comment on another comment by posix_monad.
What we want to express here is an object with a map of properties (name to type):
string Type map
For the OOP minded: Map<string, Type>
And also compose those: type Foo = { "_foo", int }
type Bar = { "_bar", string }
type FooBar = mergeMaps Foo Bar
But at compile-time, of course.Have any languages achieved this? I know TypeScript can do some of these things, but it's clunky.
This is the kind of problem you face in your first year working, no? I am honetly curious what others think. Do you have trouble deciding when to use an interface (assuming your language has that), or a type wrapper (I don't think that's the brightest idea), or a function to extract the field to sort by (most languages do that)??
interface Timestamped {
timestamp: UTCTime;
}
interface Msg {
sender: PlayerId;
}
class Quote implements Timestamped, Msg {
timestamp: UTCTime;
sender: PlayerId;
}
Why is this so hard in Haskell? It doesn't have interface polymorphism?Who says that and what does it even suppose to mean?
Complex types and objects don't exist.
Embrace Mereological Nihilism.
It's fun at meetups to tell everyone your programming paradigm is Nihilism.
interfaces describe behavior, types describe shape and structure. the difference is subtle but important.
This text should not fascinate a programmer but create frustration of two types: (1) Frustration on one's lack of small pieces knowledge (2) Frustration that NOW you will not have the chance to invent this on your ow; your creative process takes damage.
Out of which the second type should be the one that makes majority of cases.
ALSO this should cause one to have respect of form: "hey, this programmer was probably at least smart enough to figure out this alone."
Perhaps most polite woule be to, for every text, in the situation to have notice at beginning: "For programmers who already have thought about what would happen were you to add X to Y but so that Z enough to probably not to get new ideas in this context."
Related
Interface Upgrades in Go (2014)
The article delves into Go's interface upgrades, showcasing their role in encapsulation and decoupling. It emphasizes optimizing performance through wider interface casting, with examples from io and net/http libraries. It warns about complexities and advises cautious usage.
A reckless introduction to Hindley-Milner type inference (2019)
Hindley-Milner type inference balances expressiveness and legibility in programming languages like Elm and Haskell. It enhances correctness by enforcing strict type checking, limiting coding practices for improved type safety.
Ergonomic Self-Referential Types for Rust
Yoshua Wuyts introduces Ergonomic Self-Referential Types for Rust, enhancing self-referential types accessibility. Features include self lifetimes, fixed memory locations, immovable types, and safe self-references initialization. The discussion showcases async {} and Future usage, emphasizing tracking references and potential Rust type system enhancements. Collaboration with Eric Holk is acknowledged for exploring !Move implications.
Evolving Languages Faster with Type Tailoring
Programming languages face limitations in understanding domain-specific aspects like regular expressions, causing errors. "Type Tailoring" proposes teaching type systems new tricks through metaprogramming tools for improved code efficiency and correctness.
Parse, Don't Validate
The article explores type-driven design in programming, emphasizing "Parse, don’t validate" in Haskell. It showcases using types for robust code, avoiding errors, and enhancing input parsing efficiency in various tasks.