[Haskell-cafe] Re: I just don't get it (data structures and OO)
Phlex
Phlex at telenet.be
Wed Jun 6 01:00:16 EDT 2007
apfelmus wrote:
> Phlex wrote:
>
>> Ketil Malde wrote:
>>
>> 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?
>
> Regards,
> apfelmus
>
Well the current state of my haskell knowledge doesn't allow any kind of
serious work, so I'm indeed currently playing with Universe, Galaxies,
Systems, Planets and Moons =P. I'm an application programmer, and i
thought that if I can model a moving universe (a small one though!), I
guess i'll be one step closer to translating this knowledge to building
statefull server applications.
I'm worried that my OO view of things might interfere with the haskell
ways. So yes, what i'm looking for right now is more of a high level
"how-to", and that's precisely what you guys provided to me. Thanks for
that !
So here is one more question :
Let's say I want unique System names across the Universe ... that would
mean i need to have a Data.Map in the Universe, with Name keys and
System values. Since all data are values instead of references, would i
end up with two copies of each System (in Universe's Data.Map and in its
Galaxy), or would these be shared somehow ? In other words, should i go
for integer (or maybe access key/tuple) identified objects or just put
the System in both Data.Maps it belongs to ?
regards,
Sacha
More information about the Haskell-Cafe
mailing list