0

I have been playing a little bit with scalaz and I am stuck on a seemingly trivial issue. I was playing around with the Reader and Kliesli monads and found myself with something like this:

val gr = Reader { (_: Int) + 1 }
val a = gr(1)

That dutifully responds:

a: scalaz.Id.Id[Int] = 2

What I am trying to do now is to unwrap the Int from the Identity monad, for that I should be using the ?? operator, with this signature:

final def ??(d: => A)(implicit ev: Null <:< A): A

The first parameter I should pass is a default value, a call by name Int (as pointed by Brian McCutchon) :

scala> a??(1)
<console>:19: error: Cannot prove that Null <:<   scalaz.Id.Id[Int].
   a??(1)
    ^

I would like to understand what I am missing here before I keep moving. Thanks EDITED to fix my confusion about call-by-name with no parameters function. Shame.

Luis Sisamon
  • 101
  • 7
  • 1
    Not sure if I understand the problem, but .. do you actually need to unwrap it? `val a: Int = 2:scalaz.Id.Id[Int]` . You can use wrapped value the same way as unwrapped. – Bogdan Vakulenko Dec 09 '18 at 23:44
  • 1
    `=> A` is not a function that takes no parameters; that would be `() => A`. It's actually a call-by-name parameter. That explains the first error. – Brian McCutchon Dec 10 '18 at 01:19
  • @Brian, yes you are of course right – Luis Sisamon Dec 10 '18 at 19:34
  • @Bodgan, no I actually do not need to do that. But I find very annoying that I can not do it, I suspect i am missing something, that my understanding is more limited than I though – Luis Sisamon Dec 10 '18 at 19:36

1 Answers1

0

a is already an Int; see the definition.

edit: There are no methods to unwrap because there is nothing to unwrap; the type the REPL prints for a is just another way of saying Int.