[Haskell-beginners] How to nest arbitrary things

martin martin.drautzburg at web.de
Mon Dec 21 09:40:28 UTC 2015


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?



More information about the Beginners mailing list