Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Add monadic versions of data types and abstractions? #62

Open
chshersh opened this issue Jul 28, 2019 · 0 comments
Open

[RFC] Add monadic versions of data types and abstractions? #62

chshersh opened this issue Jul 28, 2019 · 0 comments

Comments

@chshersh
Copy link

I've discovered that if contravariant data types have access to a monad, it's possible to implement monadic versions of them:

newtype Predicate m a = Predicate
    { getPredicate :: a -> m Bool
    }

newtype Comparison m a = Comparison
    { getComparison :: a -> a -> m Ordering
    }

newtype Op m a b = Op
    { getOp :: b -> m a
    }

class ContravariantM t where
    cmapM :: Monad m => (a -> m b) -> t m b -> t m a

class DivisibleM t where
    divide :: Monad m => (a -> m (b, c)) -> t m b -> t m c -> t m a

class DecidableM t where
    decide :: Monad m => (a -> m (Either b c)) -> t m b -> t m c -> t m a

Monadic contravariant functions like the above ones are used in co-log. Does it make sense in general to have such abstractions? And do they have a proper name?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant