Answer by nlim for Implementing this OO concept in Haskell
This is how I would model your scenario: I would not glom together Car and Truck to fit under one sum type. Sum types are not intended to describe some commonality of data between types (but rather a...
View ArticleAnswer by Emil for Implementing this OO concept in Haskell
My initial gut reaction to your question is to implement this using the state monad, which duplode hints at in his answer. Here is a way to also accomplish what you want where the code somewhat...
View ArticleAnswer by Michal Gajda for Implementing this OO concept in Haskell
If you really want a class, it would like this:class Vehicle a where driveOneMile :: a -> Doubledata Truck = Truck -- Fill in the details...data Car = Car -- Fill in the details...instance Vehicle...
View ArticleAnswer by duplode for Implementing this OO concept in Haskell
Classes in Haskell are quite different from OO classes, and using them as if you were writing OO code in most cases makes things more complicated than they should be. In particular, as soon as you...
View ArticleImplementing this OO concept in Haskell
I need help translating an OO concept into Haskell.Imagine a Vehicle class and Car and Truck subclasses, with a driveOneMile method that returns a double representing the total fuel used. Each call to...
View Article
More Pages to Explore .....