[Haskell-cafe] Is there a way to make this code compose generic ?
Li-yao Xia
lysxia at gmail.com
Fri Apr 25 08:32:23 UTC 2025
> Do you know if there is some performance issue to use a new class for this ?
>
> How can I be sure that all the method are statically resolve at the compile time ?
In principle there shouldn't be any impact on performance. Type classes are resolved at compile time, and you only use the generic implementations at known types. All of the relevant dictionaries are known at compile-time, so with enough inlining and simplification the generic constructors and other indirections should be eliminated.
In practice, inlining is still very heuristic, so you have to look at the generated code and maybe add INLINEABLE annotations and tweak other things to make sure it happens. The inspection-testing library (https://hackage.haskell.org/package/inspection-testing) enables automated tests that make sure that the code optimized by the compiler doesn't contain certain constructs that indicate missed inlining opportunities.
Cheers,
Li-yao
More information about the Haskell-Cafe
mailing list