[scala] Eta expansion and function values

View: New views
2 Messages — Rating Filter:   Alert me  

[scala] Eta expansion and function values

by Jesper Nordenberg :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The following came up after a discussion in the IRC channel:

List(Some(1), None) flatMap identity[Option[Int]]

works fine, but:

val id = identity[Option[Int]] _
List(Some(1), None) flatMap id

doesnt work. "(id(_))" works though.

I can understand the reason why this happens, but still I find it
confusing and inconsistent. Can the implicit conversion rules for
function values and eta expansion be made more consistent?

/Jesper Nordenberg


Re: [scala] Eta expansion and function values

by tmorris :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jesper Nordenberg wrote:

> The following came up after a discussion in the IRC channel:
>
> List(Some(1), None) flatMap identity[Option[Int]]
>
> works fine, but:
>
> val id = identity[Option[Int]] _ List(Some(1), None) flatMap id
>
> doesnt work. "(id(_))" works though.
>
> I can understand the reason why this happens, but still I find it
> confusing and inconsistent. Can the implicit conversion rules for
> function values and eta expansion be made more consistent?
>
> /Jesper Nordenberg
>
>
>
Hi Jesper,
I was about to "WTF!? That shouldn't type-check!", then I realised
List.flatMap is broken. Maybe this has something to do with it. You
could write a repaired example for any difference perhaps?


- --
Tony Morris
http://tmorris.net/

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIcnRnmnpgrYe6r60RAmt7AKCd0G+3pMyh7NYm3X2c0//jrd7uHQCaA3Tp
3Nt/4X+IC0/A2QpVm6thPug=
=IgGm
-----END PGP SIGNATURE-----