FunctionalProgrammingSimplified
FunctionalProgrammingSimplified copied to clipboard
Missing interface object on Typeclass 101
In page 797, BehavesLikeHuman.speak(rover)
won't compile since we only have instances definition, but have not yet defined interface object, the following is missing:
object BehavesLikeHuman {
def speak[A](creature : A)(implicit humanLike : BehavesLikeHuman[A]) = humanLike.speak(creature)
}
Personally, I prefer to just call this interface Speaking
instead of behaves like human.
Example gist I find easier to read https://gist.github.com/wibisono/28d8808159e0c7103042d7c5c668edf7