Skip to content

Commit

Permalink
Add examples for soas functions
Browse files Browse the repository at this point in the history
  • Loading branch information
fizruk committed Oct 27, 2024
1 parent fface1c commit e2a7fc8
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions haskell/soas/src/Language/SOAS/Impl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,16 @@ type Constraint = Constraint' Raw.BNFC'Position Foil.VoidS
type OpTyping = OpTyping' Raw.BNFC'Position Foil.VoidS

-- | Lookup a substitution by its 'Raw.MetaVarIdent'.
--
-- >>> lookupSubst "?m" ["?n[] ↦ Zero()", "?m[x y] ↦ App(y, x)"]
-- Just ?m [x0 x1] ↦ App (x1, x0)
lookupSubst :: Raw.MetaVarIdent -> [Subst] -> Maybe Subst
lookupSubst m = find $ \(Subst _loc m' _ _) -> m == m'

-- | Apply meta variable substitutions to a term.
--
-- >>> applySubsts Foil.emptyScope ["?m[x y] ↦ Lam(z. App(z, App(x, y)))"] "Lam(x. ?m[App(x, ?m[x, x]), x])"
-- Lam (x0 . Lam (x2 . App (x2, App (App (x0, ?m [x0, x0]), x0))))
applySubsts :: Foil.Distinct n => Foil.Scope n -> [Subst] -> Term n -> Term n
applySubsts scope substs term =
case term of
Expand Down

0 comments on commit e2a7fc8

Please sign in to comment.