3 ms·
This approach seems to be what people new to Haskell gennerally go to first (probably because it is the natural solution given the type system). However, as muc
by gizmo686 13y ago
This approach seems to be what people new to Haskell gennerally go to first (probably because it is the natural solution given the type system). However, as much as we Haskellers hate to admit it, there are design patterns in Haskell that can offer more maintainable solutions that what the language naively presents.
In this case, a common pattern is to copy the OO concept of casting. For example, instead of having:
class Render a where
render :: a -> IO()
we could have:
class Renderable a where
toRender a -> Render
along with:
data Render = ...
render :: Render -> IO()
render r = ...
This leads to some noise with needing to put a bunch of toRender functions in a short amount of code, but this problem does not get worse as complexity increases.