Created
July 4, 2019 19:21
-
-
Save cgibbard/ba3c78252092e36570f093e30afcf682 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 GADTs #-} | |
import Reflex | |
import Data.Dependent.Map (DMap) | |
import qualified Data.Dependent.Map as DMap | |
import Data.Dependent.Sum (DSum(..)) | |
import Data.GADT.Compare | |
import Data.Functor.Compose | |
import Data.Functor.Identity | |
data KComp k v a where | |
KComp :: k a -> KComp k v (v a) | |
instance GEq k => GEq (KComp k v) where | |
geq (KComp x) (KComp y) = case geq x y of | |
Nothing -> Nothing | |
Just Refl -> Just Refl | |
instance GCompare k => GCompare (KComp k v) where | |
gcompare (KComp x) (KComp y) = case gcompare x y of | |
GLT -> GLT | |
GEQ -> GEQ | |
GGT -> GGT | |
dmShift :: DMap k (Compose (Event t) v) -> DMap (KComp k v) (Event t) | |
dmShift m = DMap.fromDistinctAscList [ KComp k :=> e | k :=> Compose e <- DMap.toAscList m] | |
dmUnshift :: DMap (KComp k v) Identity -> DMap k v | |
dmUnshift m = DMap.fromDistinctAscList [ k :=> v | KComp k :=> (Identity v) <- DMap.toAscList m ] | |
mergeG :: (Reflex t, GCompare k) => DMap k (Compose (Event t) v) -> Event t (DMap k v) | |
mergeG = fmap dmUnshift . merge . dmShift |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment