News for hackers. Stuff that matters.
Re:Thinking in Types by gizmo686 on Friday May 02, 2014 @08:04PM (#7688923)
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.

There are no comments on this comment yet.