-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move old implementation of FCU and start one with new syntax
- Loading branch information
1 parent
8582dfe
commit 6d0fab1
Showing
14 changed files
with
151 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
module Language.Lambda.FCU.FCUImplSW.Discharge where | ||
|
||
import Language.Lambda.FCU.FCUImplSW.Terms (Id, Term (..)) | ||
|
||
-- | Discharge a term by replacing all terms t in s with variables z. | ||
discharge :: [(Term, Id)] -> Term -> Term | ||
discharge th t = case lookup t th of | ||
Just y -> O y | ||
Nothing -> case t of | ||
(x :.: t1) -> x :.: discharge th t1 | ||
(t1 :@ t2) -> discharge th t1 :@ discharge th t2 | ||
t -> t | ||
|
||
-- >>> discharge [("Cons" :@ "x" :@ "y", "z")] ("Cons" :@ "x" :@ "y") | ||
-- z | ||
|
||
-- >>> discharge [("Fst" :@ "x", "z")] ("Cons" :@ ("Fst" :@ "x") :@ "w") | ||
-- (Cons z) (w) |
12 changes: 6 additions & 6 deletions
12
src/Language/Lambda/FCU/Prune.hs → src/Language/Lambda/FCU/FCUImplSW/Prune.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/Language/Lambda/FCU/RTerms.hs → src/Language/Lambda/FCU/FCUImplSW/RTerms.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
src/Language/Lambda/FCU/Restrictions.hs → ...uage/Lambda/FCU/FCUImplSW/Restrictions.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
module Language.Lambda.FCU.FCUImplSW.Strip where | ||
|
||
import Language.Lambda.FCU.FCUImplSW.Terms (Id, Term (..)) | ||
|
||
-- | Strip a term into a head and a list of arguments. | ||
strip :: Term -> (Term, [Term]) | ||
strip (t1 :@ t2) = | ||
let (h, rest) = strip t1 | ||
in (h, rest ++ [t2]) | ||
strip t = (t, []) | ||
|
||
--- >>> strip ("X" :@ "y" :@ "z") | ||
-- (X,[y,z]) | ||
|
||
--- >>> strip ("Cons" :@ "x" :@ ("y" :@ ("z" :.: "z"))) | ||
-- (Cons,[x,y λz . (z)]) | ||
|
||
-- | Combine a head term with arguments to reconstruct the original term | ||
unstrip :: (Term, [Term]) -> Term | ||
unstrip (head, args) = foldl (:@) head args | ||
|
||
-- >>> unstrip ("X", ["y", "z"]) | ||
-- (W "X" :@ O "y") :@ O "z" | ||
|
||
-- >>> ("X" :@ "y" :@ "z") | ||
-- (W "X" :@ O "y") :@ O "z" | ||
|
||
-- >>> unstrip ("Cons", ["x", "y" :@ ("z" :.: "z")]) | ||
-- (Constructor "Cons" :@ O "x") :@ (O "y" :@ ("z" :.: O "z")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 8 additions & 8 deletions
16
src/Language/Lambda/FCU/Unification.hs → ...guage/Lambda/FCU/FCUImplSW/Unification.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
module Language.Lambda.FCU.PPTerm where | ||
|
||
import Data.String | ||
import qualified Language.Lambda.FCU.FCUSyntax.ErrM as Raw | ||
import qualified Language.Lambda.FCU.FCUSyntax.Abs as Raw | ||
import qualified Language.Lambda.FCU.FCUSyntax.Par as Raw | ||
|
||
|
||
showRaw :: Raw.Term -> String | ||
showRaw term = case term of | ||
Raw.WTerm (Raw.MetavarId x) -> x | ||
Raw.OTerm (Raw.Id x) -> x | ||
Raw.CTerm (Raw.ConstructorId x) -> x | ||
Raw.AppTerm t1 t2 -> addParens $ showRaw t1 ++ " " ++ showRaw t2 | ||
Raw.AbsTerm (Raw.Id x) t -> "λ" ++ x ++ " . " ++ showRaw t | ||
where | ||
addParens s = "(" ++ s ++ ")" | ||
|
||
instance Show Raw.Term where | ||
show :: Raw.Term -> String | ||
show = showRaw | ||
|
||
instance IsString Raw.Term where | ||
fromString :: String -> Raw.Term | ||
fromString s = case Raw.pTerm . Raw.myLexer $ s of | ||
Raw.Ok term -> term | ||
Raw.Bad err -> error $ "Parse error: " ++ err | ||
|
||
-- >>> Raw.AppTerm (Raw.AppTerm (Raw.CTerm (Raw.ConstructorId "Cons")) (Raw.OTerm (Raw.Id "x"))) (Raw.OTerm (Raw.Id "y")) | ||
-- ((Cons x) y) | ||
|
||
|
||
-- >>> "X" :: Raw.Term | ||
-- X |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters