RosettaCodeData/Task/Call-an-object-method/Haskell/call-an-object-method.hs

10 lines
217 B
Haskell

data Obj = Obj { field :: Int, method :: Int -> Int }
-- smart constructor
mkAdder :: Int -> Obj
mkAdder x = Obj x (+x)
-- adding method from a type class
instanse Show Obj where
show o = "Obj " ++ show (field o)