alvinj / FunctionalProgrammingSimplified

Notes and projects for my book, “Functional Programming, Simplified"
18 stars 2 forks source link

Missing interface object on Typeclass 101 #18

Open wibisono opened 6 years ago

wibisono commented 6 years ago

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