add Functor etc for IfConsistent
This commit is contained in:
parent
7895fa37e5
commit
f959dc28fe
2 changed files with 29 additions and 9 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue