[Haskell-beginners] Representing a subset relationship

Levi Stephen levi.stephen at gmail.com
Mon Aug 4 01:12:05 EDT 2008


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20080804/61c96102/attachment.htm


More information about the Beginners mailing list