SteveGilham / fsharp-typeclasses

Automatically exported from code.google.com/p/fsharp-typeclasses
Apache License 2.0
8 stars 2 forks source link

Monoid a => Applicative ((,) a) but restricted to lists #2

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Implemented in 
http://code.google.com/r/mauricioscheffer-fsharp-typeclasses/source/detail?r=d10
13cf83bdaa90eb391e274ab00ec6049d3fe8a

I wonder if this could be generalized for any monoid.

Also investigating if general functor/applicative composition could be encoded, 
as in 
http://hackage.haskell.org/packages/archive/transformers/latest/doc/html/src/Dat
a-Functor-Compose.html#Compose

Original issue reported on code.google.com by mauricio...@gmail.com on 28 Jul 2012 at 10:58

GoogleCodeExporter commented 9 years ago
Thanks for your work.

// I wonder if this could be generalized for any monoid.

Yes, but you need to wrap it.
In fact it is already in the library as the Writer Monad, but it's missing his 
applicative instance.
However, because every Monad is an Applicative Functor, you can always use ap:

(+) <<|>  (Writer (3 , [44;55] )) </ap/> ( Writer (9, [1;2]) )

Regarding general functor/applicative compsition, looks interesting. Do you 
have code (obviously in Haskell) samples?

Original comment by gustavo....@gmail.com on 30 Jul 2012 at 10:21

GoogleCodeExporter commented 9 years ago
Thanks, I didn't see the connection to the Writer monad.

Here's a simple example of applicative composition, composing the unwrapped 
Writer with itself: https://gist.github.com/3227164

Original comment by mauricio...@gmail.com on 1 Aug 2012 at 2:14

GoogleCodeExporter commented 9 years ago
Thanks, very interesting.
Yes, it is also possible to encode it.
See the attached file (tested with revision 118).
Feel free add it to the project if you want.

Original comment by gustavo....@gmail.com on 19 Aug 2012 at 10:09

Attachments:

GoogleCodeExporter commented 9 years ago
Amazing! It's going to take me some time to understand how that works :-)

Original comment by mauricio...@gmail.com on 19 Aug 2012 at 10:45

GoogleCodeExporter commented 9 years ago
Here's the full code.

Original comment by gustavo....@gmail.com on 20 Aug 2012 at 5:24

Attachments: