Dear Scala users, I'm reading through the Functional Programming in Scala book and in the Monoids chapter, they talk about a Monoid interface that looks like this:
Later on, they define specific Monoid instances by extending this interface. For example.,
A couple more pages that I read through this chapter 10, I come across 'higher kinded types (HKT)' which according to the book is any type that it self is a type that can take other types.
So the trait Foldable is according to the book a higher kinded type. My question is, the Monoid[A] to me is also fits the 'higher kinded type' definition as it can take a List[A]
So is my listMonoid function an implementation of the Monoid[A] HKT? Thanks, Joe You received this message because you are subscribed to the Google Groups "scala-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. For more options, visit https://groups.google.com/d/optout. |
On Tue, Apr 18, 2017 at 6:24 AM, Joe San <[hidden email]> wrote:
-- You received this message because you are subscribed to the Google Groups "scala-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. For more options, visit https://groups.google.com/d/optout. |
In reply to this post by Joe San
Hi Joe, Monoid is a type constructor that accepts proper types. Foldable is a type constructor that accepts another type constructor. That makes Foldable a HKT, and Monoid not. Whether you can create a Monoid[List[A]] for any proper type A or not doesn't really matter. You cannot pass a type constructor to the Monoid type constructor thus it is not a HKT. Kind regards, Jasper Op dinsdag 18 april 2017 12:25:01 UTC+2 schreef Joe San:
You received this message because you are subscribed to the Google Groups "scala-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. For more options, visit https://groups.google.com/d/optout. |
The listmonoid method has the method type [A]Monoid[List[A]]. Meaning that from any type A it can create a value of type Monoid[List[A]]. But the List[A] that you pass to Monoid is still a proper type, not a type constructor. The property of being higher kinded is not really ascribed to methods (value level) but to type constructors (type level). Maybe it would be possible to say of a method type that it's higher kinded, but listmonoid still isn't. I imagine a method type [F[_]]Monoid[F[Int]] could be considered higher kinded. I'm also no expert on type theory. Op 18 apr. 2017 16:50 schreef "Joe San" <[hidden email]>:
You received this message because you are subscribed to the Google Groups "scala-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. For more options, visit https://groups.google.com/d/optout. |
Free forum by Nabble | Edit this page |