This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Re: Option as applicative functor

No replies
marius
Joined: 2008-08-31,
User offline. Last seen 3 years 19 weeks ago.
Yes indeed ...

On Sat, Aug 6, 2011 at 4:05 PM, Tony Morris <tonymorris [at] gmail [dot] com> wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You could say that about an enormous number of traits.

There is a "growing movement" of people who delay introduction of the
unit operation, so you'd have a trait with ap+fmap instead (semigroups
instead of monoids).

On 06/08/11 23:03, Marius Danciu wrote:
> Right, but I guess here could have been an Applicative[T[_]] trait that
> those type constructors such as Option would mixin with, avoiding copy-paste
> in many cases. Applicative would probably have to extend Functor[T[_]] for
> having unit and fmap.
>
> Thanks,
> Marius
>
> On Sat, Aug 6, 2011 at 3:54 PM, Tony Morris <tonymorris [at] gmail [dot] com> wrote:
>
> Well then that would require such a method on many type constructors,
> and the body of these methods would be a copy/paste show.
>
> def <*>[B](f: F[A => B]): F[B] = for { ff <- f; aa <- this } yield ff(aa)
>
>
> On 06/08/11 22:52, Marius Danciu wrote:
>>>> Precisely.
>>>>
>>>> Marius
>>>>
>>>> On Sat, Aug 6, 2011 at 3:35 PM, Tony Morris <tonymorris [at] gmail [dot] com>
> wrote:
>>>>
>>>> On 06/08/11 21:27, Marius Danciu wrote:
>>>>>>> Hello,
>>>>>>>
>>>>>>> Is there a good reason why Scala Option is not an applicative functor
> ? I
>>>>>>> guess one could seamlessly convert an Option[T] to an Applicative[T]
>>>>  using
>>>>>>> implicits but still ..
>>>>>>>
>>>>>>> Thanks,
>>>>>>> Marius
>>>>>>>
>>>>
>>>> Which Applicative do you mean? For the one in scalaz, there is an
>>>> implementation for Option.
>>>>
>>>> Do you want a method on Option[T] taking an Option[T => U], returning
>>>> Option[U]?
>>>>
>>>>
>>>>>
>
>>

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

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

iQEcBAEBAgAGBQJOPTwJAAoJEPxHMY3rBz0PPK0IALCCSVUxZ3Uv37LQhdkA1QJ1
LlkFaJ9dFoSwqoPDe7WxuqxnWTNe12iNc7op5Mw00Ql2bSa8V7sOfVSMaj+oyxeO
Ci+QlO633wjTcsfPbcPugJ6usqN/EM6Dm0rMx/c7eeKxIktzhKT7x+vq4c29H4Ru
lG5SjMscm6teN9MMuCeCcTl1RklymAl6YvETemM1AQW3H1SNmFDpKRUyLAbkj0Vj
HuiDBzDy/4MhLj79zJTFG+/MMAOra0c99QQJ0vJvpRoHZvAhNC8y9MdOpq/h+nH3
M4prjgvG3/PyIeyVJI0p5ZJ66QnyqTJPRH/xORTMkf6hDLZhos0cJq8PMpTAVIw=
=T2dK
-----END PGP SIGNATURE-----

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland