Can i make it a monad

I have a type T (which, if you're interested, is a wrapper for static pointers that I studied here ), where I can happily write the following operations for:

 unpointT :: T a -> a apT :: T (a -> b) -> T a -> T b bindT :: T a -> (a -> T b) -> T b 

The problem is that I do not have an unlimited pure function. pure should be limited in my case to some restriction that says the type is serializable, like Binary .

 pureT :: C a => a -> T a 

Please note that both apT and bindT are unlimited.

It all looks like a monad, but with the only problem, which is limited purity. Is there anyway, possibly with some GADT wrapping / unwrapping, that I can get this to work with the standard Monad hierarchy?

If not, is there an alternative hierarchy that restricts pure but preserves <*> and >>= unlimited?

Note also that T a may be valid for some a , although pure (x :: a) not, for example, by combining T (b -> a) and T b with ap .

+5
source share
1 answer

This will not work as if it were a monad, because the law of law is not satisfied.

bindT m pureT is of type C a => T a bindT m pureT , and m is of type bindT m pureT . These two should always be equal, but they are not even of the same type.

0
source

Source: https://habr.com/ru/post/1276289/


All Articles