RosettaCodeData/Task/Call-an-object-method/Haskell/call-an-object-method.hs
2023-07-01 13:44:08 -04:00

9 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)