[Haskell-cafe] Design of a Physics Interface

Henning Thielemann lemming at henning-thielemann.de
Fri Nov 30 09:32:26 EST 2007


On Fri, 30 Nov 2007, Luke Palmer wrote:

> But I can't figure out a good way to represent bodies in this world.
> I considered:
>
> > newBody :: (Position,Velocity) -> World -> (Body,World)
>
> Where Body is an ADT with an internal representation of an Integer or
> something.  The problem with this is that (1) there is no way to
> guarantee that a Body actually exists in a World (which is a minor but
> still annoying issue), and (2) that there's a possibility that you
> could make a Body in one world and use it in another and there would
> be no way to detect the error.

Is it ok to have phantom types for Body and World? This would work if the
number of worlds is fixed at compile time.

newBody :: (Position,Velocity) -> World worldId -> (Body worldId, World worldId)


More information about the Haskell-Cafe mailing list