Last active
October 8, 2018 14:49
-
-
Save sjoerdvisscher/f36676a8ba88fcfa86fce389255b74dd to your computer and use it in GitHub Desktop.
Monoid Comprehensions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE MonadComprehensions, RebindableSyntax #-} | |
import Prelude hiding (return, (>>=), (>>), guard) | |
return :: a -> a | |
return = id | |
(>>=) :: (Foldable f, Monoid m) => f a -> (a -> m) -> m | |
(>>=) = flip foldMap | |
guard :: Bool -> Bool | |
guard = id | |
(>>) :: Monoid m => Bool -> m -> m | |
(>>) True m = m | |
(>>) False _ = mempty | |
query | |
:: (Monoid m, Foldable f1, Foldable f2) | |
=> (a -> b -> Bool) -> (a -> b -> m) -> f1 a -> f2 b -> m | |
query f g xs ys = [ g x y | x <- xs, y <- ys, f x y ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment