[Haskell-cafe] Re: I just don't get it (data structures and OO)
apfelmus at quantentunnel.de
Tue Jun 5 14:21:29 EDT 2007
> Ketil Malde wrote:
>> Identity can be emulated by relatively straightforward means: store all
>> planets in a Map indexed by something that is useful as an identifier
>> (i.e. stays constant and is unique), and have a Galaxy keep a list of
> So basically you guys are saying I should rethink the data structure
> into a relational model instead of sticking to the OO model... I think i
> could do this pretty easily. a table would be a map of id to instance
> ....then another map for foreign keys, or maybe just as a member of each
> Is the relational model a better fit than the object model for
> functional programming ?
Well, not really. I mean, if the problem is indeed to store all known
planets in the universe, then it's indeed a database in nature and you
have to support fine grained operations like
delete :: Key -> Database -> Database
insert :: Key -> Item -> Database -> Database
... and so on ...
(Note that some proposals like
changeGalaxies $ changePlanet 0 $ changeName $ const "first"
or functional references can be interpreted as keys for 'insert' or
'delete'. I mean that this expression already is the key to look up a
planet inside the universe, it's just that this key has a rather unusual
type. And that you can compose keys.)
But if the problem at hand is perhaps a binary search tree or some other
data structure, you can implement many operations without using
per-element 'delete' or 'insert' although every operation can in
principle be built up from those. Maybe it helps if you elaborate on
your concrete problem?
More information about the Haskell-Cafe