Kleisli composition as a primitive combinator?

51 views
Skip to first unread message

Philip Schwarz

unread,
Aug 31, 2017, 1:54:33 PM8/31/17
to scala-functional

Hello,


I have put together three slides capturing how https://www.manning.com/books/functional-programming-in-scala defines a monad in terms of primitive combinators unit+flatMap, unit+compose and unit+map+join: https://twitter.com/philip_schwarz/status/902083644797399040





As you can see on the slide for unit+compose, the implementation of compose (Kleisli composition), for the list monad in this case, is left unspecified. In the answers to the book's exercises I have found an implementation of compose in terms of flatMap https://github.com/fpinscala/fpinscala/blob/master/answerkey/monads/07.answer.scala, but what does composition look like as a primitive? 

Any thoughts?

Thanks,

Philip Schwarz

pagoda_5b

unread,
Oct 20, 2017, 1:40:28 PM10/20/17
to scala-functional
I don't understand if you're asking how to implement compose as a primitive on List, or if you're generally asking what opinion we have on defining compose as one of the building blocks for the other operations...

Apart from this, the different definitions are equivalent, in the sense that to be able to define the kleisli composition for the Functor F, there must be some underlying ability to define for F operations which are equivalent to unit + join, or unit + flatMap, because that underlying capability is what makes it possible for the corresponding Kleisli to be a category and therefore to have a compose function.

I know it may sounds a bit vague, but the corresponding math is what gives meaning to the Monad definition and the operations on that.

I hope it helps, otherwise feel free to elaborate more

Ivano

Vlad Patryshev

unread,
Oct 20, 2017, 2:52:49 PM10/20/17
to scala-fu...@googlegroups.com
Ivano,

You are right; and we have to remind whoever is willing to listen that:

Kleisli category is defined for a monad. This fact can be found in  "Categories for the Working Mathematicians", if the voice of reason is not enough.

Thanks,
-Vlad

--
You received this message because you are subscribed to the Google Groups "scala-functional" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-functional+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages