Skip to content

Instantly share code, notes, and snippets.

@dminuoso

dminuoso/f.hs Secret

Last active June 1, 2021 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dminuoso/fef54010b5d7dd475245d6f9b6546737 to your computer and use it in GitHub Desktop.
Save dminuoso/fef54010b5d7dd475245d6f9b6546737 to your computer and use it in GitHub Desktop.
deriving instance Functor Proof
type YESP = Yoneda (Compose (Either String) Proof)
applyPropRule :: Path -> (Proof (PropCalc a)
-> Either String (Proof (PropCalc a)))
-> Proof (PropCalc a)
-> Either String (Proof (PropCalc a))
applyPropRule xs f (Proof x) = getCompose
. lowerYoneda
$ go xs (f . liftYoneda . Compose) x
where
go :: Path
-> (Proof (PropCalc a) -> YESP (PropCalc a))
-> PropCalc a
-> YESP (PropCal a)
go (_:xs) f (Not x) = go xs f x <&> Not
go (GoLeft:xs) f (And x y) = go xs f x <&> (`And` y)
go (GoLeft:xs) f (Or x y) = go xs f x <&> (`Or` y)
go (GoLeft:xs) f (Imp x y) = go xs f x <&> (`Imp` y)
go (GoRight:xs) f (And x y) = go xs f x <&> (x `And`)
go (GoRight:xs) f (Or x y) = go xs f x <&> (x `Or`)
go (GoRight:xs) f (Imp x y) = go xs f x <&> (x `Imp`)
go _ f x = f (Proof x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment