Skip to content

Commit

Permalink
Merge pull request #777 from explorable-viz/maybeJoin
Browse files Browse the repository at this point in the history
Drop `BoolAlg` and explicit dom/codom on `GaloisConnection`. Add `Category` instance.
  • Loading branch information
rolyp authored Sep 28, 2023
2 parents ed9759a + a7bdf03 commit 132b463
Show file tree
Hide file tree
Showing 19 changed files with 105 additions and 1,839 deletions.
68 changes: 0 additions & 68 deletions src/BoolAlg.purs

This file was deleted.

13 changes: 6 additions & 7 deletions src/Desug.purs
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
module Desug where

import Desugarable (desug, desugBwd)
import Prelude

import Control.Monad.Error.Class (class MonadError)
import Desugarable (desug, desugBwd)
import Effect.Exception (Error)
import Expr (Expr)
import GaloisConnection (GaloisConnection)
import Lattice (Raw, class BoundedJoinSemilattice)
import GaloisConnection (GaloisConnection(..))
import Lattice (class BoundedJoinSemilattice, Raw)
import SExpr (Expr) as S
import Util (successful)

type DesugGaloisConnection a = GaloisConnection (S.Expr a) (Expr a) ()

desugGC
:: forall a m
. MonadError Error m
=> BoundedJoinSemilattice a
=> Raw S.Expr
-> m (DesugGaloisConnection a)
-> m (GaloisConnection (S.Expr a) (Expr a))
desugGC s0 = do
let
fwd s = successful $ desug s
bwd e = desugBwd e s0
pure { fwd, bwd }
pure $ GC { fwd, bwd }
12 changes: 0 additions & 12 deletions src/Desugarable2.purs

This file was deleted.

7 changes: 4 additions & 3 deletions src/Dict.purs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ import Util (Endo, type (×), (×), assert, definitely, error)

type Dict a = O.Object a

-- `Apply` instance would be an orphan
apply :: forall a b. Dict (a -> b) -> Dict a -> Dict b
apply d ds = intersectionWith ($) d ds
apply = intersectionWith ($) -- why not require dicts to have same shape?

apply2 :: forall f a b. Apply f => Dict (f (a -> b)) -> Dict (f a) -> Dict (f b)
apply2 d ds = apply ((<*>) <$> d) ds
apply2 d = apply ((<*>) <$> d)

lift2 :: forall f a b c. Apply f => (a -> b -> c) -> Dict (f a) -> Dict (f b) -> Dict (f c)
lift2 f d1 d2 = apply2 ((f <$> _) <$> d1) d2
lift2 f d1 = apply2 ((f <$> _) <$> d1)

-- Unfortunately Foreign.Object doesn't define this; could implement using Foreign.Object.ST instead.
foreign import intersectionWith :: forall a b c. (a -> b -> c) -> Dict a -> Dict b -> Dict c
Expand Down
176 changes: 0 additions & 176 deletions src/Eval2.purs

This file was deleted.

19 changes: 7 additions & 12 deletions src/EvalBwd.purs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module EvalBwd where

import Prelude hiding (absurd)

import BoolAlg (BoolAlg, slicesγ, slices, prod)
import Bindings (Var, varAnon)
import Control.Monad.Except (class MonadError, runExcept)
import Data.Exists (mkExists, runExists)
Expand All @@ -22,7 +20,7 @@ import Dict (fromFoldable, singleton, toUnfoldable) as D
import Effect.Exception (Error)
import Eval (eval)
import Expr (Cont(..), Elim(..), Expr(..), RecDefs, VarDef(..), bv)
import GaloisConnection (GaloisConnection)
import GaloisConnection (GaloisConnection(..))
import Lattice (Raw, bot, botOf, expand, (∨))
import Partial.Unsafe (unsafePartial)
import Trace (AppTrace(..), Trace(..), VarDef(..)) as T
Expand Down Expand Up @@ -197,18 +195,15 @@ evalBwd' v (T.LetRec ρ t) =
γ1' × ρ' × α' = closeDefsBwd γ2
evalBwd' _ _ = error absurd

type EvalGaloisConnection a = GaloisConnection (Env a × Expr a × a) (Val a)
( dom :: BoolAlg (Env a × Expr a × a)
, codom :: BoolAlg (Val a)
type TracedEval a =
{ gc :: GaloisConnection (Env a × Expr a × a) (Val a)
, v :: Raw Val
)
}

traceGC :: forall a m. MonadError Error m => Ann a => BoolAlg a -> Raw Env -> Raw Expr -> m (EvalGaloisConnection a)
traceGC 𝒶 γ e = do
traceGC :: forall a m. MonadError Error m => Ann a => Raw Env -> Raw Expr -> m (TracedEval a)
traceGC γ e = do
t × v <- eval γ e bot
let
dom = slicesγ 𝒶 γ `prod` (slices 𝒶 e `prod` 𝒶)
codom = slices 𝒶 v
bwd v' = evalBwd γ e v' t
fwd (γ' × e' × α) = snd $ fromRight $ runExcept $ eval γ' e' α
pure { dom, codom, v, fwd, bwd }
pure $ { gc: GC { fwd, bwd }, v }
Loading

0 comments on commit 132b463

Please sign in to comment.