<div dir="ltr"><div>Hi Haskell-Cafe,<br></div><div><br></div><div>I've been experimenting with indexed/parameterized monads with a single "parameter" type variable.<br></div><div>The difference from my variation from Conor McBride's IMonad (which also uses one "parameter") is that the "parameter" doesn't have postcondition semanatics.</div><div><br></div><div>(FYI, a good intro to indexed monads is <a href="https://stackoverflow.com/questions/28690448/what-is-indexed-monad">https://stackoverflow.com/questions/28690448/what-is-indexed-monad</a>)</div><div><br></div><div>Instead, in the instance of PApplicative, you have to specify the rule of how to combine the "parameter" `t` and `u` into the final parameter `u`.</div><div><br></div><div>That way, I can create "parameterized" versions of Semigroup, Monoid, as well as Applicative, Alternative, Monad.</div><div><br></div><div>It also allows for create different flavours of "parameterized" kinds for ReaderT.</div><div><br></div><div>For example, I've created OverlappingWhichReader, DistinctWhichReader, and ManyReader newtype wrappers around ReaderT.</div><div><br></div><div>OverlappingWhichReader and DistinctWhichReader can combine reader that read `Which '[Int, Bool]` (polymorphic variant, analogous to 'Either Int Bool') with another reader that reader `Which '[Bool, String]` into a reader that can read `Which '[Int, Bool, String]`</div><div><br></div><div>ManyReader can combine reader that read `Many '[Int, Bool]` (heterogenous record, analogous to tuple (Int, Bool)) with another reader that reader `Many '[Bool, String]` into a reader that can read `Many '[Int, Bool, String]`</div><div><br></div><div>See <a href="https://github.com/louispan/parameterized/blob/master/src/Parameterized/Control/Monad/Trans/Reader.hs">https://github.com/louispan/parameterized/blob/master/src/Parameterized/Control/Monad/Trans/Reader.hs</a><br></div><div><a href="https://github.com/louispan/parameterized/blob/master/test/Parameterized/Control/Monad/Trans/Reader/ReaderSpec.hs">https://github.com/louispan/parameterized/blob/master/test/Parameterized/Control/Monad/Trans/Reader/ReaderSpec.hs</a><br></div><div><br></div><div>-----</div><div><br></div><div>The single "parameter" still allows for the traditional changing state type for StateT.</div><div>For example, I've created ChangingState newtype wrappers around StateT, which changes the state parameter.</div><div><div><br></div><div>I've also created ManyState, which can combine StateT that modifies `Many '[Int, Bool]` with another StateT that modifes `Many '[Bool, String]` into a StateT that can modify `Many '[Int, Bool, String]`</div><div><br></div><div>See <a href="https://github.com/louispan/parameterized/blob/master/src/Parameterized/Control/Monad/Trans/State/Strict.hs">https://github.com/louispan/parameterized/blob/master/src/Parameterized/Control/Monad/Trans/State/Strict.hs</a></div></div><div><a href="https://github.com/louispan/parameterized/blob/master/test/Parameterized/Control/Monad/Trans/State/Strict/StateSpec.hs">https://github.com/louispan/parameterized/blob/master/test/Parameterized/Control/Monad/Trans/State/Strict/StateSpec.hs</a><br></div><div><br></div><div>---</div><div><br></div><div>I'd would appreciate if I could get any feedback on this approach.</div><div><br></div><div>Cheers,</div><div><br></div><div>Louis</div><div><div class="gmail_extra"><br></div></div></div>