[Haskell-beginners] Representing a subset relationship

Daniel Fischer daniel.is.fischer at web.de
Mon Aug 4 09:23:36 EDT 2008

Am Montag, 4. August 2008 07:12 schrieb Levi Stephen:
> Hi,
> I was wondering what the best way to represent a 'subset' type relationship
> would be. The use case I'm looking at is where the subset would be a user
> selection, so a filter would not be appropriate.
> For example, say I have something like:
> type Order = [OrderItem]
> type OrderItem = OrderItem { qty :: Int, product: Product }
> Now I'd like the user to be able to select a number of items (e.g.,
> priority shipping, gift wrapping)
> One possible way  I can see is to add extra fields to the OrderItem record,
> but this seems like it would not be easy to extend.
> It doesn't seem like  using [Product] would be appropriate as if the
> Product is updated it will need to be updated in both the OrderItem list
> and in the subset.
> Another approach would be to use a ProductIdType in place of Product, then
> look up the actual Product as needed.
> Are there other (and better) ways to do this?
> Thanks,
> Levi

Perhaps something like 

data Extra
	= PriorityShipping
	| GiftWrapping ...

data OrderItem
	= OrderItem { qty :: Int, product :: Product, extras :: [Extra] }


Or make it

type Quantity = Int
type Order = [(Product, Quantity, [Extras])]



More information about the Beginners mailing list