
martin writes:
Hello all,
I was trying to model things which can contain other things. This is easy as long as containers and the contained items all can be described in the same fashion. However when I want to model - say -
trucks containing boxes containing parcels containing cans
and trucks, boxes, parcels and cans are not of the same type, then this nested thing will become a type in its own right and it will be of a different type than trucks containing cans (which are not wrappen in parcels ...)
As long as I can squeeze trucks, boxes ... into one type, possibly by using a "container_type" attribute, there is no problem. Is this the only way to do this? Is there an idiom?
Well, you can always make Truck a bit generic: data Truck a = Truck [a] Then you have have a truck of boxes (`Truck Box`) or a truck of cans (`Truck Can`). But maybe that's not really your question? /M -- Magnus Therning OpenPGP: 0x927912051716CE39 email: magnus@therning.org jabber: magnus@therning.org twitter: magthe http://therning.org/magnus Any sufficiently advanced technology is indistinguishable from a rigged demo. -- Andy Finkel