Object-oriented Haskell surprisingly appealing
github.com
github.com
"This work developed out of an initial attempt to understand the actorness of actors... we discovered that the 'actors' and the lambda expressions were identical in implementation."
https://dspace.mit.edu/bitstream/handle/1721.1/5794/AIM-349....
It looked like mathier version of OCaml written classic object oriented way, not half bad. Didn't get traction. It was mostly defined in standard Haskell.
data Set a = Set { contains :: a -> Bool }
which leaves the actual structure of the set undefined. This means you can use a variety of methods 'under the surface' to compute set membership and the external interface can be identical and compatible: emptySet = Set { contains = \_ -> False }
singletonSet x = Set { contains = \y -> x == y }
union l r = Set { contains = \y -> contains l y && contains r y }
fromList lst = Set { contains = \y -> y `elem` lst }
And while this example is a bit trivial, this pattern is invaluable for writing things that OOP can traditionally excel at, like writing GUIs or certain kinds of video games where you want to bundle heterogeneous behavior into a single package: data GameObject = GameObject
{ render :: Pos -> GraphicsContext -> IO ()
, currentPosition :: Pos
, setPosition :: Pos -> GameObject
}
Of course, this is only one (significantly simpler!) encoding of OOP, and it might not be one that you think captures the key ideas of objects, but to the degree that it is it demonstrates that ideas which are common in OOP (like information-hiding behind an interface) can still be useful in Haskell when judiciously applied in the right context.The paper I cited can be read here, which has more details: https://www.cs.utexas.edu/~wcook/Drafts/2009/essay.pdf