`size` Question from https://milessabin.com/blog/2012/05/10/shapeless-polymorphic-function-values-2/
kevinmeredith opened this issue · comments
Intro
My question applies to your well-written https://milessabin.com/blog/2012/05/10/shapeless-polymorphic-function-values-2/.
Failed to Post
I tried to post the following question to the blog itself, but I got this error:
Question
For my own understanding, why must a Type Lambda be used for the size
object?
As I partially and incompletely understand, a Type Lambda provides a const
function for types, i.e. const :: a -> b -> a
.
That being said, why is it not sufficient to use the following instead of a Type Lambda?
scala> type IntOnly[A] = Int
defined type alias IntOnly
and then define size
as follows?
scala> object size extends PolyFunction1[List, IntOnly] {
| def apply[T](t: List[T]): IntOnly[T] = t.length
| }
defined object sized
The only difference is that a type lambda can be defined inline, anonymously.
Sorry about the comment posting issue.
Sorry about the comment posting issue.
No problem. Thanks for this excellent series of blog posts!