-
-
Save Lysxia/a6c953f7aafd6775b8d279337dc7040a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 DeriveFunctor #-} | |
| {-# LANGUAGE DeriveTraversable #-} | |
| {-# LANGUAGE DeriveFoldable #-} | |
| import Control.Monad | |
| import Data.Foldable | |
| data Entry a = Any | Every a | Exactly a | Many [a] | |
| deriving (Eq, Ord, Show, Functor, Foldable, Traversable) | |
| instance Applicative Entry where | |
| pure = Exactly | |
| (<*>) = ap | |
| instance Monad Entry where | |
| m >>= f = myJoin (fmap f m) | |
| myJoin :: Entry (Entry a) -> Entry a | |
| myJoin Any = Any | |
| myJoin (Many xs) = Many (concatMap toList xs) | |
| myJoin (Every (Every x)) = Every x | |
| myJoin (Every (Exactly x)) = Every x | |
| myJoin (Every (Many xs)) = Many xs | |
| myJoin (Every Any) = Any | |
| myJoin (Exactly y) = y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment