haskell - If MonadPlus is the "generator" class, then what is the "consumer" class? -


A pipe can be broken into two parts: generator Part ( yield ) and consumer section ( wait )

If you have pipes it uses only the generator, and returns only () (or never returns), then It can be displayed in the form of " ListT correct", it has come to know that MonadPlus can be used to represent anything correctly. Could.

So my question is: what is double

P>

() (or never return), but the form of "dual to list" using awaiting Can be done in

  • "Text">

    I think the answer is "type generator" type-class, rather it's class / (> wait) / ( > pipe instead of expanding with a simple category example equals the class.

    Unfortunately, there is no way to manage type variables to satisfy all three types of classes ( MonadPlus , MonadTrans , and < Code> category ), so I will define a new type class:

      {- # LANGUAGE type sharing # -} Import control. Main import control Currency. Trance Class class consumer (T :: * - & gt; (* - & gt; *) -> * * - & gt; *) Wait where: T one m one (& gt; ~) :: T an M B - & gt; TBMC - & gt; Tamc  

    There are law class law categories:

      wait; Gt; F = ff> ~ Await = f (f> ~ G) & gt; Once you have this additional type of class:  
      printer :: (Show, MonaD (Ta Io), Monad Trance (Ta) ), Consumer T) = & gt; An IOR printer = a & lt; - Wait for the Lift printer (printer: Show = => Consumer IOR printer = a & lt; - lift ( Print) - Cat :: (Monadplus (TAM), consumer T) => t one m one cat = wait `mplus` cat {- Cat :: Monad M => Pipe A A MR B Ll = a & lt; - waiting for a cat to be produced -} Debug :: (Show, a MonadPlus (an Io), MonadTrans (TA), Consumer T) = IO One debug = a & lt; - Wait for Lift (print A) to return a `mplus` debug (- debug :: show a = & gt; pipe ao r debug = a & lt; - wait for lift (print) generate debug - Laser :: (Consumer T, Monadplus (TA M)) => int -> t one m taker 0 = mzero taker n = a & lt; - a `mplus` taker (n - 1) Waiting for return {- taker :: Monad M = & Gt; Int - & gt; Pipe mango () laser 0 = return () lake n = a & lt; - Waiting for recipient to recipient (N-1) -}  

    The hard part is to find out how to do this: Adding a new type of class to Base If possible, want to reuse the original category type class, possibly having waiting and (& gt; ~) There are functions that type in a new type, use the category example, and then open it, but I'm still Also, I am doing special work of how to do it.

    Edit: I got the solution. Just define the following types of innovation:

      {- # language type authoring, Flexible Contexus # -} Import Control. Celebrity Import Predded Hide (id.), Id) newtype consumer tmab = consumer {unsuspector :: template} wait :: category (consumer TM) => One m one wait = Unsetting ID (& gt; ~) :: Category (Consumers TM) = & gt; T one mb - & gt; TBMC - & gt; Tamcf & gt; ~ G = unConsumer (Consumer F & G;> Consumer G)  

    Then any library should implement a class example for their type In the consumer newtype

    Then you wait for or (& gt; ~) :

      cat :: (monadplus ), Category (consumer TM)) = & gt; T one m one cat = wait `mplus` cat  

  • Comments

    Popular posts from this blog

    sqlite3 - UPDATE a table from the SELECT of another one -

    c# - Showing a SelectedItem's Property -

    javascript - Render HTML after each iteration in loop -