3

I'm learning Scalaz recently. I would like to know how λ[α =>F] works?

scala> Applicative[λ[α => Int]].point(10)
res45: Int = 0

scala> Applicative[λ[α => String]].point(10)
res46: String = ""

I can understand λ means some type here, but I could not find its definition and would like to know how the above code works.

Dmytro Mitin
  • 48,194
  • 3
  • 28
  • 66
Binzi Cao
  • 1,075
  • 5
  • 14
  • Lambda that takes a (anything) and returns an Int (first one) or a String (second one). If you come from imperative programming you can think of it as a pointer to a function int foo(Object a) and string foo(Object a). But don't tell functional programmers that you think this way, they tend to get angry. – v010dya Sep 21 '15 at 04:44
  • Thanks! I'd like to know how the λ type works, There must be some code about the λ. Because I could not change λ to a different name, such as T. Applicative[T[α => String]].point(10) does not work – Binzi Cao Sep 21 '15 at 04:56

1 Answers1

2

scalaz use kind-projector.

Applicative[λ[α => Int]] is equivalent to Applicative[({type l[a] = Int})#l]

Kenji Yoshida
  • 3,108
  • 24
  • 39