add Functor etc for IfConsistent

This commit is contained in:
rhiannon morris 2023-02-20 21:38:47 +01:00
parent 7895fa37e5
commit f959dc28fe
2 changed files with 29 additions and 9 deletions

View file

@ -29,10 +29,36 @@ data DimEq : Nat -> Type where
public export
data IfConsistent : DimEq d -> a -> Type where
consistent : DimEq d -> Bool
consistent ZeroIsOne = False
consistent (C eqs) = True
public export
data IfConsistent : DimEq d -> Type -> Type where
Nothing : IfConsistent ZeroIsOne a
Just : a -> IfConsistent (C eqs) a
export
Functor (IfConsistent eqs) where
map f Nothing = Nothing
map f (Just x) = Just (f x)
export
Foldable (IfConsistent eqs) where
foldr f z Nothing = z
foldr f z (Just x) = f x z
export
Traversable (IfConsistent eqs) where
traverse f Nothing = pure Nothing
traverse f (Just x) = Just <$> f x
public export
ifConsistent : Applicative f => (eqs : DimEq d) -> f a -> f (IfConsistent eqs a)
ifConsistent ZeroIsOne act = pure Nothing
ifConsistent (C _) act = Just <$> act
export %inline
zeroEq : DimEq 0