3

Gabriel Gonzalez in his blog post describes a way to purify code using free monads. Let's say we have FreeMonadIO a, then we can write different interpreters, for example, one for testing purposes and one for actual IO.

I wonder if something similar could be done for Arrows. Something like FreeArrowIO a b, which would be a pure representation of a computation with side effects and with an explicit input, which then could be interpreted in different ways (one of them is IO).

I know that I can write something like FreeArrowIO = Kleisli FreeMonadIO, but is there a way to skip monad step and define FreeArrowIO directly?

starper
  • 175
  • 1
  • 8
  • 1
    Something like [this](http://stackoverflow.com/q/12001350/477476), maybe? – Cactus Jan 18 '16 at 03:21
  • @Cactus thanks. I've already read both the question and the answer, but I'm not sure that I fully understand what's going on there. As for the question I'm not quite sure how `eff a b` should look like, my guess is that it is a pure function wrapped in a type constructor, but how should I interpret it then? I mean other than just apply a function? As for the answer it's too theoretical for me, I'm not very good in theory (yet, I hope). Can you please explain it somehow simpler? – starper Jan 18 '16 at 11:59
  • 1
    "how should I interpret it then" - isn't that the point? It is completely up to you. If you've got a value of type `forall eff . FreeArrow eff a b` then it was built without any additional assumptions about the underlying structure. This is identical to a value `forall arr . Arrow arr => arr x y` - this is essentially what it means to be a "free" structure. If your `eff` is IO for example, you could represent this as `data IO_Eff a b where PutStr :: IO_Eff String (); GetLine :: IO_Eff () String; ...` - can you see how you would write a function `forall a b . IO_Eff a b -> Kleisli IO a b`? – user2407038 Jan 18 '16 at 16:57
  • @user2407038 thanks. Now I get it. In `Operational` and `Free` monad base functor should wrap some value and (for some unknown reason) I thought that `eff a b` should too and had a hard time trying to understand what value it should be. Now I see how it should be done. – starper Jan 20 '16 at 11:08

0 Answers0