[Haskell-cafe] OOP'er with (hopefully) trivial questions.....
ketil+haskell at ii.uib.no
Mon Dec 17 06:10:04 EST 2007
"Nicholls, Mark" <Nicholls.Mark at mtvne.com> writes:
> After many years of OOP though my brain is wired up to construct software in
> that ?pattern??.a problem for me at the moment is I cannot see how to construct
> programs in an OO style in Haskell?.I know this is probably not the way to
> approach it?but I feel I need to master the syntax before the paradigm.
Mostly, you'd use an algebraic data type. I.e.
data Shape = Square Int | Rectangle Int Int | Circle Int
area :: Shape -> Int
area (Square x) = x^2
area (Rectangle x y) = x * y
area (Circle r) = pi*r^2
If I haven't seen further, it is by standing in the footprints of giants
More information about the Haskell-Cafe