View Problem
Instantiate object with mutable state
Reimplement the Greeter class so that the
For example, if the greetee is changed to
Hello, Tommy!
The getter would then be used to display the line:
I have just greeted Tommy.
Submit a new solution for fsharp, fantom, groovy, or haskell
There are 11 other solutions in additional languages (clojure, cpp, csharp, java ...)
'whom' property or data member remains private but is mutable, and is provided with getter and setter methods. Invoke the setter to change the greetee, invoke 'greet', then use the getter in displaying the line, "I have just greeted {whom}.".
For example, if the greetee is changed to
'Tommy' using the setter, the 'greet' method would display:
Hello, Tommy!
The getter would then be used to display the line:
I have just greeted Tommy.
haskell
data Greeter = G { greeting :: String, greetee :: String }
class Greets a where
greet :: a -> IO ()
instance Greets Greeter where
greet g = print (greeting g)
main = do
let g = G { greeting = "Hello", greetee = "{whom}" }
greet g
print $ "I have just greeted " ++ greetee g { greetee = "Tommy" }
class Greets a where
greet :: a -> IO ()
instance Greets Greeter where
greet g = print (greeting g)
main = do
let g = G { greeting = "Hello", greetee = "{whom}" }
greet g
print $ "I have just greeted " ++ greetee g { greetee = "Tommy" }
Submit a new solution for fsharp, fantom, groovy, or haskell
There are 11 other solutions in additional languages (clojure, cpp, csharp, java ...)


