4 ms·
I am a big proponent of functional programming, but there are situations where it would be veeerrryy convenient to have open types and inheritance, which is for
by rrradical 12y ago
I am a big proponent of functional programming, but there are situations where it would be veeerrryy convenient to have open types and inheritance, which is forbidden in a language like Haskell.
Modelling something like a GUI toolkit is very difficult in Haskell, because each widget has a different clump of data associated with it. Functional programming works well when the data is uniform, or at least known ahead of time. It's very difficult to add new data structures into the system in a dependent module, like if you want to add a custom widget type. In OO, this is trivial.
I'm not sure what the best solution is. People are researching alternative solutions (namely FRP), but it's too bad it's necessary in the first place.
- codygman 12y ago> like if you want to add a custom widget type Add a custom widget from a gui program itself? So it's a gui program that has a widget builder then? Why not have an abstract data type which lets you encode the properties of both of those?
- rrradical 12y agoI'm talking about supplementing a toolkit. Like, in iOS or gtk or QT or whatever, there are stock widgets (buttons, sliders, text boxes), but you can also add your own widgets, like a date picker. A date picker would be modeled completely differently from those other widgets, and so it needs a completely different data structure. This requires supplementing the existing types, which isn't possible in Haskell.
- codygman 12y agoThat date picker inherits from something though right?
- rrradical 12y agoRight. In OO, you can inherit, but in Haskell, you can't.
- codygman 12y agohttp://yi-editor.github.io/2014/09/05/oop/ http://yi-editor.github.io/2014/09/05/oop/
- codygman 12y agoAlso, I'm not sure why you'd need to inherit to provide this functionality. The user could just provide a monadic type the function to run the gui is expecting and extend it however they wish.
- rrradical 12y agoI won't claim to be an expert on this stuff-- I've only recently been studying this. But, from my understanding, if you have a tree of GUI elements, each of those elements needs to have the same type, and that type needs to be known ahead of time. It's possible I don't understand your comment. Would you mind pointing me to some sample code or blog post or something?