Difference between Unit and ()

100 views
Skip to first unread message

Piotr Kukiełka

unread,
Mar 4, 2015, 8:17:05 AM3/4/15
to scala-i...@googlegroups.com
Looks like scala threats () => Unit and Unit => Unit differently.
This is reproducible with both REPL and scalac.
Is that intended behavior or a bug?

scala> val f1 = () => ()
f1: () => Unit = <function0>

scala> val failure: Unit => Unit = f1
<console>:8: error: type mismatch;
 found   : () => Unit
 required: Unit => Unit
       val failure: Unit => Unit = f1
                                   ^

scala> val f2 = (_: Unit) => ()
f2: Unit => Unit = <function1>

scala> val success: Unit => Unit = f2
success: Unit => Unit = <function1>


Best regards,
Piotr

Simon Schäfer

unread,
Mar 4, 2015, 8:32:14 AM3/4/15
to scala-i...@googlegroups.com
--
You received this message because you are subscribed to the Google Groups "scala-internals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-interna...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages