Identity of simulation objects in Haskell -
writing simulation in object-oriented language, each object has identity--that is, way distinguish every other object in simulation, if other objects have exact same attributes. object retains identity, no matter how changes on time. because each object has unique location in memory, , can express location pointers or references. works if don't impose additional identity system guids. (which support things networking or databases don't think in terms of pointers.)
i don't believe there equivalent concept in haskell. so, standard approach use guids?
update clarify problem: identity important concept in problem domain 1 reason: objects have relationships each other, , these must preserved. example, haskell red car red car, , red cars identical (provided color attribute cars have). if each red car must linked owner? , if owner can repaint cars?
final update synthesizing answers: consensus seems should add identifiers data types if part of simulation use identifiers, , there's no other way express same information. e.g. case person owns multiple cars, each of has color, person can keep list of immutable cars. expresses ownership relationship long have access person.
the person may or may not need kind of unique identifier. 1 scenario occur is: there's function takes car , collection of persons , imposes parkingticket on appropriate person. car's color cannot uniquely identify person gets ticket. can give person id , have car store it.
but potentially avoided better design. perhaps our cars have additional attribute of type parkingposition, can evaluated legal or illegal. pass collection of persons function looks @ each person's list of cars, checks each one's parkingposition, , imposes parkingticket on person if appropriate. since function knows person it's looking at, there's no need car record info.
so in many cases, assigning ids not necessary first may seem.
why want "solve" non-problem? object identity problem oo languages haskell happily avoids.
in world of immutable objects, 2 objects identical values are same object. put same immutable object twice list , have 2 different objects wherever want see things way (they "both" contribute total number of elements, example, , have unique indexes) without of problems java-style reference equality causes. can save list database table , 2 different rows, if like. more need?
update
jarret, seem convinced objects in model must have genuinely separate identities because real life ones distinct. however, in simulation, matters in contexts objects need differentiated. generally, need unique identifiers in context objects must differentiated , tracked, , not outside contexts. identify contexts, map lifecycle of object important to simulation (not "real" world), , create appropriate identifiers.
you keep providing answers own questions. if cars have owners, bob's red car can distinguished carol's red car. if bob can repaint car, can replace red car blue car. need more if
- your simulation has cars without owners
- you need able distinguish between 1 ownerless red car , another.
in simple model, 1 may true , 2 not. in case, ownerless red cars same red car so why bother making them distinct?
in missile simulation, why missiles need track owning launchers? they're not aimed @ launchers! if launcher can continue control missile after launched, launcher needs know missiles owns reverse not true. missile needs know trajectory , target. when lands , explodes, significance of owner? make bigger bang if launched launcher rather launcher b?
your launcher can empty or can have n missiles still available fire. has location. targets have locations. @ 1 time there k missiles in flight; each missile has position, velocity/trajectory , explosive power. missile position coincident ground should transformed exploding missile, or dud etc etc.
in each of contexts, information important? launcher identity really important @ detonation time? why? enemy going launch retaliatory strike? no? that's not important information detonation. isn't important information after launch. launching can step number of missiles belonging launcher decremented while number of missiles in flight incremented.
now, might have answer these questions, should map model before start lumbering objects identities may not need.
Comments
Post a Comment