Suppose I have some generic function
genericFunc :: a -> b
genericFunc x = doSomeHardWork
But for a particular type, there is a much more efficient way that genericFunc
could be done.
genericFunc :: ParticularType -> b
genericFunc x = doSomeEasyWork
What is the best way to combine these two function bodies into the same genericFunc
, such that when used on ParticularType
, it will doSomeEasyWork
, but when used on other types, it will doSomeHardWork
? I'm specifically excluding the option of using a different name, or different modules.
I believe this can be done with a typeclass, but I am more interested in solutions that use language pragmas. I have a vague inkling that this can be done with language pragmas but I have no idea how. Bonus points if you compare and contrast these approaches, and/or any other possible approaches.