Created
July 21, 2020 03:31
-
-
Save tonymorris/a7a92d31d701848acb17f1617e07dba6 to your computer and use it in GitHub Desktop.
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
{-# OPTIONS_GHC -Wall #-} | |
{-# LANGUAGE TemplateHaskell #-} | |
import Control.Lens | |
data These a b = | |
This a | |
| That b | |
| Both a b | |
deriving (Eq, Show) | |
makePrisms ''These | |
is :: APrism s t a b -> s -> Bool | |
is p = not . isn't p | |
-- can this be written "more neatly", without the duplication... | |
isThisOrThat :: These a b -> Bool | |
isThisOrThat t = is _This t || is _That t | |
-- like this, except in this case, the type has changed | |
isThisOrThat' :: These a a -> Bool | |
isThisOrThat' t = any (`is` t) [_This, _That] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment