ANN: parameterized, indexed monads with a single "parameter" type variable

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

ANN: parameterized, indexed monads with a single "parameter" type variable

Louis Pan-2
Hi Haskell-Cafe,

I've been experimenting with indexed/parameterized monads with a single "parameter" type variable.
The difference from my variation from Conor McBride's IMonad (which also uses one "parameter") is that the "parameter" doesn't have postcondition semanatics.

(FYI, a good intro to indexed monads isĀ https://stackoverflow.com/questions/28690448/what-is-indexed-monad)

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`.

That way, I can create "parameterized" versions of Semigroup, Monoid, as well as Applicative, Alternative, Monad.

It also allows for create different flavours of "parameterized" kinds for ReaderT.

For example, I've created OverlappingWhichReader, DistinctWhichReader, and ManyReader newtype wrappers around ReaderT.

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]`

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]`


-----

The single "parameter" still allows for the traditional changing state type for StateT.
For example, I've created ChangingState newtype wrappers around StateT, which changes the state parameter.

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]`


---

I'd would appreciate if I could get any feedback on this approach.

Cheers,

Louis


_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.