[Haskell-cafe] dependent types

Jason Dagit dagit at codersbase.com
Sun Apr 11 19:26:40 EDT 2010


On Sun, Apr 11, 2010 at 4:15 PM, Ozgur Akgun <ozgurakgun at gmail.com> wrote:

>
> On 11 April 2010 22:54, Jason Dagit <dagit at codersbase.com> wrote:
>
>>
>>
> ...
>>
>
>>
> class Vehicle a where
>>
>> data Car
>> data Truck
>>
>> instance Vehicle Car where
>> instance Vehicle Truck where
>>
>> Now you can have things that take a Car or a Truck or they can take a
>> Vehicle instead.
>>
>> moveVehicle :: Vehicle v => v -> Simulation ()
>>
>>
> unfortunately, now you cannot use pattern matching while defining
> moveVehicle.
>

That's true.  Although, if you're writing a simulation where Cars and Trucks
are objects in that simulation, they are likely to be defined as records as
they will probably have many fields.  If that's the case, it's unlikely
you'd be using pattern matching with them anyway.  It's just a small step
from there to using typeclass functions to access the parts you care about.

Jason
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100411/813aac8b/attachment.html


More information about the Haskell-Cafe mailing list