Created
February 14, 2023 12:21
-
-
Save sjoerdvisscher/c1c6edfd4acb114e649fbb1777985f96 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
{-# LANGUAGE TypeOperators, FlexibleContexts #-} | |
import GHC.Generics ((:.:)(..)) | |
import Control.Applicative (liftA2) | |
class Applicative f => Selective f where | |
select :: f (Either a b) -> f (a -> b) -> f b | |
select fe fab = either id (uncurry (flip ($))) <$> biselect (either Right Left <$> fe) (Right <$> fab) | |
biselect :: f (Either a b) -> f (Either a c) -> f (Either a (b, c)) | |
class Applicative f => CheckClosed f where | |
checkClosed :: f a -> Maybe (f b) | |
biselectC :: (Applicative f, CheckClosed (f :.: Either a)) => f (Either a b) -> f (Either a c) -> f (Either a (b, c)) | |
biselectC fab fac = case checkClosed (Comp1 fab) of | |
Just (Comp1 fex) -> fex | |
Nothing -> liftA2 (liftA2 (,)) fab fac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment