Full Haskell-like Type Class resolution in Java
Web page · https://garciat.com/posts/java-type-classes
First seen by Oriel on .
AI summary
The post builds a plain-Java Haskell-style type class resolution engine that uses reflection, generic metadata, and type unification to derive witnesses for nested and higher-kinded types.
- Type class implementations are modeled as static witness constructors whose parameters express dependencies on witnesses for component types.
- An anonymous Ty<T> implementation captures inferred generic type information at runtime through preserved metadata on its generic interface.
- java.lang.reflect.Type values are parsed into a sealed ParsedType AST representing variables, applications, arrays, constants, and primitives.
- Resolution searches annotated public static witness methods only within the type class and concrete type definitions, avoiding a runtime scan of all loaded classes.
- A recursive first-order unifier determines applicable constructors and substitutes type variables; the experiment also supports overlapping instances but is not intended for production.
#java #type classes #type unification #higher-kinded types
Generated by gpt-5.6-sol. Check the original for details.
Metric trends
Last 30 days · Up to 120 recorded samples per source and metric, with reposts kept separate · First and latest retained
Points
Score reported by the source.
- Lobsters: 12, latest observation ; +11 over observed period since
Comments
Comment count reported by the source.
- Lobsters: 1, latest observation ; +1 over observed period since
Aliases
| Source | External ID | URL |
|---|---|---|
| Lobsters | beiiil | https://garciat.com/posts/java-type-classes/ Read discussion |