Hello!
Thank you all again for all your work on this excellent package.
I wrote instances for universe's Universe and Finite classes for the These a b type.
If you are interested in having support for these instances included then please let me know, I would gladly make a PR.
The code is pretty straight forward.
import Control.Applicative (liftA2)
import Data.Tagged (Tagged (..), retag)
import Data.Universe (Finite (..), Universe (..))
import Numeric.Natural (Natural)
toThese :: Either (Either a b) (a, b) -> These a b
toThese = either (either This That) (uncurry These)
instance (Universe a, Universe b) => Universe (These a b) where
universe :: [These a b]
universe = fmap toThese universe
instance (Finite a, Finite b) => Finite (These a b) where
-- a + b + ab
cardinality :: Tagged (These a b) Natural
cardinality = liftA2 (\a b -> a + b + a * b) (retag (cardinality :: Tagged a Natural))
(retag (cardinality :: Tagged b Natural))
universeF :: [These a b]
universeF = fmap toThese universeF
If you are not comfortable with the name toThese then it can simply be inlined to avoid giving it a name, or I am open to suggestions for a different name :)
Here are some example usages in GHCi:
λ> mapM_ print (universeF @ (These () Bool))
This ()
That False
That True
These () False
These () True
λ> cardinality @ (These () Bool)
Tagged 5
If you are not interested then I won't take offense and please close the ticket; any feedback is certainly welcomed. Thank you for your time and consideration.
Hello!
Thank you all again for all your work on this excellent package.
I wrote instances for
universe'sUniverseandFiniteclasses for theThese a btype.If you are interested in having support for these instances included then please let me know, I would gladly make a PR.
The code is pretty straight forward.
If you are not comfortable with the name
toThesethen it can simply be inlined to avoid giving it a name, or I am open to suggestions for a different name :)Here are some example usages in GHCi:
If you are not interested then I won't take offense and please close the ticket; any feedback is certainly welcomed. Thank you for your time and consideration.