Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalised unification for FreeScoped terms #4

Merged
merged 21 commits into from
Nov 5, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Change Bool -> IsHead
  • Loading branch information
fizruk committed Nov 4, 2021
commit c6bb88786a38163e556d4daae4560c4ce66b1137
13 changes: 9 additions & 4 deletions rzk/src/Rzk/Free/Syntax/FreeScoped/ScopedUnification.hs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ instance (Unifiable f, Unifiable g) => Unifiable (f :+: g) where
zipMatch (InR g1) (InR g2) = fmap InR (zipMatch g1 g2)
zipMatch _ _ = Nothing

data IsHead
= HasHead
| NoHead
deriving (Eq, Show)

class Unifiable t => HigherOrderUnifiable t where
-- | Assign a list of valid shape guesses to each subterm (and subscope).
--
Expand All @@ -90,7 +95,7 @@ class Unifiable t => HigherOrderUnifiable t where
:: t scope term
-> t (scope, [t () ()]) (term, [t () ()])

shapes :: [t Bool Bool]
shapes :: [t IsHead IsHead]
shapes = []

toHeadForm :: HigherOrderUnifiable t => FreeScoped b t a -> FreeScoped b t (Maybe a)
Expand Down Expand Up @@ -570,8 +575,8 @@ tryFlexRigid (t1 :~: t2) =
[ FreeScoped . InL <$> bitraverse goScope go shape
| shape <- shapes ]
where
go False = pure t `mplus` grow t n
go True = genFullMeta n
go HasHead = pure t `mplus` grow t n
go NoHead = genFullMeta n

-- FIXME: we are not using extra bound variables here!
goScope x = Bound.toScope . fmap Bound.F <$> go x
Expand Down Expand Up @@ -651,7 +656,7 @@ instance HigherOrderUnifiable TermF where
where
noGuesses = bimap (,[]) (,[])

shapes = [ AppF False True ]
shapes = [ AppF HasHead NoHead ]

instance Reducible TermF where
reduceInL = \case
Expand Down