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

Merge unification and system-f branches into main #7

Merged
merged 36 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
5a392ea
Use free foil on Type
fizruk Sep 18, 2024
d799c34
Sketch generic unification based on free-foil
fizruk Sep 18, 2024
a6d0089
finish type unification implementation
evermake Sep 26, 2024
f9437de
Generalize applySubstToType
fizruk Sep 26, 2024
bb0c57b
format files, fix doctests
evermake Oct 10, 2024
8dc6b35
remove unused code
evermake Oct 10, 2024
2f557f2
add grammar for `forall` (WIP)
evermake Oct 10, 2024
8934746
(WIP) update syntax for HM, add comments for an implementation, add t…
evermake Oct 10, 2024
9c2307f
implement (bad) unification
evermake Oct 18, 2024
fd8345a
add well-typed test
evermake Oct 24, 2024
edb7ea2
minor refactoring
evermake Oct 24, 2024
7df5552
add more tests
Oct 24, 2024
c0ee144
sort test files when testing
evermake Oct 24, 2024
8aeb75a
Better generalize/specialize
fizruk Oct 24, 2024
a43e72b
add tests with nested let and abstraction
Oct 27, 2024
a64ebdd
[WIP] fix generalization, add tests
evermake Oct 27, 2024
75013ec
finish generalization implementation (NEEDS TESTING)
evermake Oct 28, 2024
2df13ee
Merge branch 'unification' of github.com:evermake/free-foil-hm into u…
Oct 31, 2024
b477351
renaming of tests
Oct 31, 2024
b525fbe
fix well-typed test 019
Nov 4, 2024
ed00eb2
update types upon new substs
Nov 4, 2024
a44c5d0
Use TypeCheck monad
fizruk Nov 5, 2024
334b009
WIP: tests with expected type
evermake Nov 14, 2024
90473fc
test: update tests no to eval and compare with expected type
evermake Nov 17, 2024
f9feebd
restore generalization in algorithm
Nov 20, 2024
59bac20
add expected to 18-19 well-typed and simplify tests
Nov 21, 2024
aba703e
rename spec file
evermake Nov 21, 2024
ca72833
Fix ambiguous grammar for Type
fizruk Nov 21, 2024
e17a284
fix comparison of types in tests
Nov 22, 2024
760ea2e
rename package `free-foil-hm` to `free-foil-typecheck`, rename `HM` t…
evermake Jan 20, 2025
914a9dc
move system-f branch, rename modules, reorganize directories
evermake Jan 23, 2025
4dedd3a
Fix typechecking
fizruk Jan 31, 2025
9010381
fix paths for test files
evermake Feb 6, 2025
6697530
remove broken doctests
evermake Feb 6, 2025
b67d63e
Merge branch 'main' into merge-branches
evermake Feb 6, 2025
d8e518b
update "Current Progress" section in README
evermake Feb 6, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
stack-version: 'latest'

- name: Build
run: stack build free-foil-hm
run: stack build free-foil-typecheck

- name: Test
run: stack test
2 changes: 1 addition & 1 deletion .github/workflows/haddock.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
stack-version: 'latest'

- name: Build Haddock
run: stack haddock free-foil-hm
run: stack haddock free-foil-typecheck

- name: Detect Haddock path
run: echo "HADDOCK_DIR_PATH=$(stack path --local-doc-root)" >> $GITHUB_ENV
Expand Down
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ Current goals are:

## Current progress

At the moment, our work in this repository is divided into two branches: [`system-f`](https://github.com/evermake/free-foil-typecheck/tree/system-f) and [`unification`](https://github.com/evermake/free-foil-typecheck/tree/unification), where you can find our current results on bidirectional typing and Hindley-Milner-style type inference, respectively. Currently, we're working on implementation of type checking and type inference algorithms for a concrete small language.
Our work in this repository contains implementations of bidirectional typing (System F) and Hindley-Milner-style type inference. Currently, we're working on implementing type checking and type inference algorithms for a concrete small language.

Both branches have the same directory structure:
- `grammar/` — BNFC grammar describing our concrete language syntax.
- `src/` — source code of type checker.
- `app/` — source code of REPL and interpreter binaries for playing with the current implementation.
- `test/` — scripts and test-cases with input programs for testing type checker functionality.
The repository has the following directory structure:
- `grammar/` — BNFC grammars describing concrete language syntaxes.
- `src/` — source code of type inference and type checking algorithms.
- `app/` — source code of REPL and interpreter binaries for playing with the current implementations.
- `test/` — scripts and test-cases with input programs for testing type checkers functionality.

Contents of the mentioned directories are divided for Hindley-Milner and System F implementations.

---

[^1]: Nikolai Kudasov, Renata Shakirova, Egor Shalagin, and Karina Tyulebaeva. 2024. Free Foil: Generating Efficient and Scope-Safe Abstract Syntax. In 2024 4th International Conference on Code Quality (ICCQ). 1–16. https://doi.org/10.1109/ICCQ60895.2024.10576867
[^2]: Abdelrahman Abounegm, Nikolai Kudasov, and Alexey Stepanov. 2024. Teaching Type Systems Implementation with Stella, an Extensible Statically Typed Programming Language. In Proceedings of the Thirteenth Workshop on Trends in Functional Programming in Education, South Orange, New Jersey, USA, 9th January 2024 (Electronic Proceedings in Theoretical Computer Science, Vol. 405), Stephen Chang (Ed.). Open Publishing Association, 1–19. https://doi.org/10.4204/EPTCS.405.1
Expand Down
14 changes: 12 additions & 2 deletions Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,22 @@ main =
[ "chcp.com" | isWindows ] <>
[ "chcp.com 65001" | isWindows ] <>
[ "cp grammar/hindley-milner.cf grammar/Parser.cf" -- Workaround to customize generated package name
, "bnfc --haskell -d -p HM --generic -o src grammar/Parser.cf"
, "bnfc --haskell -d -p FreeFoilTypecheck.HindleyMilner --generic -o src grammar/Parser.cf"
, "rm grammar/Parser.cf"
, "cd src/HM/Parser"
, "cd src/FreeFoilTypecheck/HindleyMilner/Parser"
, "alex Lex.x"
, "happy Par.y"
, "true"
, "cd ../../../.."
] <>
[ "cp grammar/system-f.cf grammar/Parser.cf" -- Workaround to customize generated package name
, "bnfc --haskell -d -p FreeFoilTypecheck.SystemF --generic -o src grammar/Parser.cf"
, "rm grammar/Parser.cf"
, "cd src/FreeFoilTypecheck/SystemF/Parser"
, "alex Lex.x"
, "happy Par.y"
, "true"
, "cd ../../../.."
]

fullCommand = [fmt|bash -c ' {command} '|]
Expand Down
18 changes: 18 additions & 0 deletions app/HindleyMilner/Interpreter.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Main where

import FreeFoilTypecheck.HindleyMilner.Interpret
import System.Exit

main :: IO ()
main = do
sourceCode <- getContents
case interpret sourceCode of
Success (outExpr, _) -> putStrLn (show outExpr)
Failure errorKind errorMsg -> do
putStrLn errorMsg
exitWith (ExitFailure (errorCode errorKind))

errorCode :: ErrorKind -> Int
errorCode ParsingError = 1
errorCode TypecheckingError = 2
errorCode EvaluationError = 3
14 changes: 7 additions & 7 deletions app/Repl.hs → app/HindleyMilner/Repl.hs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module Main where

import Control.Monad.Foil (emptyScope, emptyNameMap)
import HM.Eval
import HM.Parser.Par
import HM.Syntax (toExpClosed)
import HM.Typecheck
import Control.Monad.Foil (emptyScope)
import FreeFoilTypecheck.HindleyMilner.Eval
import FreeFoilTypecheck.HindleyMilner.Parser.Par
import FreeFoilTypecheck.HindleyMilner.Syntax (toExpClosed)
import FreeFoilTypecheck.HindleyMilner.Typecheck

main :: IO ()
main = do
Expand All @@ -15,10 +15,10 @@ repl :: String -> String
repl input =
case toExpClosed <$> pExp tokens of
Left err -> "Parsing error: " ++ err
Right e -> case inferType emptyNameMap e of
Right e -> case inferTypeNewClosed e of
Left err -> "Typechecking error: " ++ err
Right _type -> case eval emptyScope e of
Left err -> "Evaluation error: " ++ err
Left err -> "Evaluation error: " ++ err
Right outExp -> show outExp
where
tokens = myLexer input
3 changes: 2 additions & 1 deletion app/Interpreter.hs → app/SystemF/Interpreter.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
module Main where

import HM.Interpret
import FreeFoilTypecheck.SystemF.Interpret
import System.Exit

main :: IO ()
-- main = undefined
main = do
sourceCode <- getContents
case interpret sourceCode of
Expand Down
24 changes: 24 additions & 0 deletions app/SystemF/Repl.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module Main where

import Control.Monad.Foil (emptyNameMap)
import FreeFoilTypecheck.SystemF.Eval
import FreeFoilTypecheck.SystemF.Parser.Par
import FreeFoilTypecheck.SystemF.Syntax (toTermClosed)
import FreeFoilTypecheck.SystemF.Typecheck

main :: IO ()
main = do
putStrLn "Welcome to REPL!\n"
interact (unlines . map repl . lines)

repl :: String -> String
repl input =
case toTermClosed <$> pTerm tokens of
Left err -> "Parsing error: " ++ err
Right e -> case inferType emptyNameMap e of
Left err -> "Typechecking error: " ++ err
Right _type -> case eval emptyNameMap e of
Left err -> "Evaluation error: " ++ err
Right outExp -> show outExp
where
tokens = myLexer input
143 changes: 0 additions & 143 deletions free-foil-hm.cabal

This file was deleted.

Loading