arrows

Cases in which we shall not use monadic bind to write mfix down using loop

有些话、适合烂在心里 提交于 2021-02-07 13:22:53
问题 I have been trying to write mfix down using Control.Arrow.loop. I came up with different definitions and would like to see which one is mfix 's actual workalike. So, the solution I reckon to be the right one is the following: mfix' :: MonadFix m => (a -> m a) -> m a mfix' k = let f ~(_, d) = sequenceA (d, k d) in (flip runKleisli () . loop . Kleisli) f As one can see, the loop . Kleisli 's argument works for Applicative instances. I find it to be a good sign as we mostly have our knot-tying

Cases in which we shall not use monadic bind to write mfix down using loop

佐手、 提交于 2021-02-07 13:21:11
问题 I have been trying to write mfix down using Control.Arrow.loop. I came up with different definitions and would like to see which one is mfix 's actual workalike. So, the solution I reckon to be the right one is the following: mfix' :: MonadFix m => (a -> m a) -> m a mfix' k = let f ~(_, d) = sequenceA (d, k d) in (flip runKleisli () . loop . Kleisli) f As one can see, the loop . Kleisli 's argument works for Applicative instances. I find it to be a good sign as we mostly have our knot-tying

Hughes' Fibonacci stream

戏子无情 提交于 2021-01-26 08:23:12
问题 I am trying to understand the "Streams as arrows" section in John Hughes' famous "Generalising Arrows to Monads". To be more precise, I am interested in writing down the Fibonacci stream. I tweaked Hughes' definition a bit: data StreamProcessor a b = Get (a -> StreamProcessor a b) | Put b (StreamProcessor a b) | Halt put = Put get = Get First of all, I treat stream processors as lists which may block (waiting for input). That is: Put :: b -> StreamProcessor a b -> StreamProcessor a b matches