On 2012-01-23 13.45.50 -0800, David Barbour wrote:
> If your classes are more like `interfaces`, you could use Typeclasses to
> model them. Otherwise, look into OOHaskell. But I think your program
> architecture will simply be different in idiomatic Haskell than in
> idiomatic C++.

If your OO is very design patterned, and especially if it prefers
composition over inheritence, you can port it sorta directly, sometimes.

For example, all the classes that implement an interface become a sum
type, and their methods are functions that take a value of the sum type.

    interface MusicCompilation { def trackListing() : [Song] }
    class Record implements MusicCompilation { ... }
    class BlogPost implements MusicCompilation { ... }

Could translate to

    data MusicCompilation = Record [Song] | BlogPost [Song]

    trackListing (Record xs) = xs
    trackListing (BlogPost xs) = xs

The more your OO looks like C, the harder this will be.

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to