Question: I'm writing a custom module for one of my projects and I'm having a bit of an issue. What I'm trying to do is get a piece of data from uc\_cart\_get\_contents() into a variable so that I can use it in a calculation: 

Here's my var\_export:

```
array ( )array ( 0 => stdClass::__set_state(array( 'cart_item_id' => '5', 'cart_id' => '1', 'nid' => '9', 'qty' => '10', 'changed' => '1287074120', 'data' => array ( 'attributes' => array ( 3 => '4', ), 'shippable' => '1', 'restrict_qty' => '0', 'module' => 'uc_product', ), 'title' => 'Chicago Canyon', 'vid' => '9', 'cost' => 1.16, 'price' => 11.16, 'weight' => 0, 'module' => 'uc_product', 'model' => 'chicago-canyon-p-card-p-env', )), )

```

But what if I want to put the model of each item in the cart into a variable, and based upon that variable adjust the item's price.

If it was an array I would do this:

```
$items= uc_cart_get_contents();

$model = $items[model];

```

but that doesn't work, it's a std class. I'm so so lost. Please help!

Answer: 
Er, not really, no.

For one thing, Haskell's type classes don't have constructors; data types do.

Also, a type class instance isn't really attached to the type it's defined for, it's more of a separate entity. You can import instances and data definitions separately, and usually it doesn't really make sense to think about "what class(es) does this piece of data belong to". Nor do functions in a type class have any special access to the data type an instance is defined for.

What a type class actually defines is a collection of identifiers that can be shared to do conceptually equivalent things (in some sense) to different data types, on an explicit per-type basis. This is why it's called *ad-hoc polymorphism*, in contrast to the standard *parametric polymorphism* that you get from regular type variables.

It's much, much closer to "overloaded functions" in some languages, where different functions are given the same name, and dispatch is done based on argument types (for some reason, other languages don't typically allow overloading based on return type, though this poses no problem for type classes).
This slideshow may help you understand the similarities and differences between OO abstract classes and Haskell type classes: [Classes, Jim, But Not As We Know Them](http://www.springerlink.com/index/77607141463259g4.pdf).