Journal entry for


Some thoughts on Objects in FRP.

Denotative Identity and Objects, Denotative Object-Oriented Programming

I see identity (in the sense of an object having an identity) as a problem in our current functional programming practice. It seems that we invent it over and over again whenever we need it, manually generating identifiers and tracking whatever values are supposed to be associated with that identifier. Or, we go the impure route and use mutable references and revert back to impure imperative programming.

I think we can do better than that with FRP-like semantics.

Identity

I’ve worked on generating unique identifiers in FRP before. Semantically these are something like a list of (Time,Index), which note the causality of the identifier. I.e. “what are the moments in time that lead to this particular identifier being generated?”

type Identifier = [(Time,Natural)]

The Natural here is “the n-th identifier generated at a particular moment with this chain of causality”. I’m not very satisfied with that, it feels like the definition of the program should somehow be included there as well? Semantically at least. When you implement identifiers the number index works fine.

Object definition

I’m considering an object as something with an identity and a state which can change over time. This can be modeled as a pair of Identifier and Behavior.

type Object a = (Identifier, Behavior a)

Interface

instance Eq Identifier

getId :: Now Identifier

new :: Behavior a -> Now (Object a)

instance Eq (Object s) where
  (a, _) == (b, _) = a == b

Objects can be compared for equality by comparing their identity. There is no aliasing problem because the definition of their state cannot be modified.

Future work