├── .gitignore ├── README.md ├── blog ├── .gitignore ├── css │ ├── custom.css │ └── syntax.css ├── deploy.sh ├── drafts │ └── nb │ │ ├── srclocs.md │ │ └── testing.md ├── index.md ├── little-languages-blog.cabal ├── posts │ ├── b.md │ ├── b │ │ ├── semantics.md │ │ ├── testing.md │ │ └── text.md │ ├── i.md │ ├── i │ │ ├── testing.md │ │ └── text.md │ ├── n.md │ ├── nb.md │ └── packages │ │ └── quickcheck.md ├── site.hs └── templates │ ├── default.html │ ├── index.html │ ├── post-list.html │ └── post.html ├── code ├── .gitignore ├── b │ ├── .DS_Store │ ├── .gitignore │ ├── LICENSE │ ├── Setup.hs │ ├── b.cabal │ ├── default.nix │ ├── repl │ │ └── Main.hs │ ├── shell.nix │ ├── src │ │ ├── Common │ │ │ ├── .DS_Store │ │ │ ├── Gen.hs │ │ │ ├── Parse.hs │ │ │ └── Pretty.hs │ │ ├── Term.hs │ │ ├── Term │ │ │ ├── Eval │ │ │ │ ├── BigStep.hs │ │ │ │ ├── SmallStep.hs │ │ │ │ └── Value.hs │ │ │ ├── Gen.hs │ │ │ ├── Infer.hs │ │ │ ├── Parse.hs │ │ │ ├── Parse │ │ │ │ └── Zoo.hs │ │ │ ├── Pretty.hs │ │ │ └── Pretty │ │ │ │ └── Zoo.hs │ │ ├── Type.hs │ │ └── Type │ │ │ ├── Error.hs │ │ │ ├── Error │ │ │ └── Pretty.hs │ │ │ ├── Gen.hs │ │ │ ├── Parse.hs │ │ │ └── Pretty.hs │ ├── stack.yaml │ └── tests │ │ ├── Test.hs │ │ ├── Test │ │ ├── Term.hs │ │ ├── Term │ │ │ ├── Eval.hs │ │ │ ├── Infer.hs │ │ │ ├── Structure.hs │ │ │ └── Text.hs │ │ ├── Type.hs │ │ └── Type │ │ │ └── Text.hs │ │ └── doctests.hs ├── i │ ├── .DS_Store │ ├── LICENSE │ ├── Setup.hs │ ├── default.nix │ ├── i.cabal │ ├── repl │ │ └── Main.hs │ ├── shell.nix │ ├── src │ │ ├── Common │ │ │ ├── .DS_Store │ │ │ ├── Parse.hs │ │ │ ├── Pretty.hs │ │ │ └── Text.hs │ │ ├── Term.hs │ │ ├── Term │ │ │ ├── Eval │ │ │ │ ├── BigStep.hs │ │ │ │ ├── SmallStep.hs │ │ │ │ └── Value.hs │ │ │ ├── Gen.hs │ │ │ ├── Infer.hs │ │ │ ├── Parse.hs │ │ │ └── Pretty.hs │ │ ├── Type.hs │ │ └── Type │ │ │ ├── Error.hs │ │ │ ├── Error │ │ │ └── Pretty.hs │ │ │ ├── Gen.hs │ │ │ ├── Parse.hs │ │ │ └── Pretty.hs │ ├── stack.yaml │ └── tests │ │ ├── Test.hs │ │ ├── Test │ │ ├── Common.hs │ │ ├── Common │ │ │ └── Text.hs │ │ ├── Term.hs │ │ ├── Term │ │ │ ├── Eval.hs │ │ │ ├── Infer.hs │ │ │ ├── Structure.hs │ │ │ └── Text.hs │ │ ├── Type.hs │ │ └── Type │ │ │ └── Text.hs │ │ └── doctests.hs ├── n │ ├── LICENSE │ ├── Setup.hs │ ├── default.nix │ ├── n.cabal │ ├── repl │ │ └── Main.hs │ ├── shell.nix │ ├── src │ │ ├── Common │ │ │ ├── .DS_Store │ │ │ ├── Parse.hs │ │ │ └── Pretty.hs │ │ ├── Term.hs │ │ ├── Term │ │ │ ├── Eval │ │ │ │ ├── BigStep.hs │ │ │ │ ├── BigStep │ │ │ │ │ ├── Lazy.hs │ │ │ │ │ └── Strict.hs │ │ │ │ ├── SmallStep.hs │ │ │ │ ├── SmallStep │ │ │ │ │ ├── Lazy.hs │ │ │ │ │ └── Strict.hs │ │ │ │ ├── Value.hs │ │ │ │ └── Value │ │ │ │ │ ├── Lazy.hs │ │ │ │ │ └── Strict.hs │ │ │ ├── Gen.hs │ │ │ ├── Infer.hs │ │ │ ├── Parse.hs │ │ │ └── Pretty.hs │ │ ├── Type.hs │ │ └── Type │ │ │ ├── Error.hs │ │ │ ├── Error │ │ │ └── Pretty.hs │ │ │ ├── Gen.hs │ │ │ ├── Parse.hs │ │ │ └── Pretty.hs │ ├── stack.yaml │ └── tests │ │ ├── Test.hs │ │ ├── Test │ │ ├── Term.hs │ │ ├── Term │ │ │ ├── Eval.hs │ │ │ ├── Eval │ │ │ │ ├── Lazy.hs │ │ │ │ └── Strict.hs │ │ │ ├── Infer.hs │ │ │ ├── Structure.hs │ │ │ └── Text.hs │ │ ├── Type.hs │ │ └── Type │ │ │ └── Text.hs │ │ └── doctests.hs ├── nb │ ├── LICENSE │ ├── Setup.hs │ ├── default.nix │ ├── nb.cabal │ ├── repl │ │ └── Main.hs │ ├── shell.nix │ ├── src │ │ ├── Common │ │ │ ├── .DS_Store │ │ │ ├── Parse.hs │ │ │ └── Pretty.hs │ │ ├── Term.hs │ │ ├── Term │ │ │ ├── Eval │ │ │ │ ├── BigStep.hs │ │ │ │ ├── BigStep │ │ │ │ │ ├── Lazy.hs │ │ │ │ │ └── Strict.hs │ │ │ │ ├── SmallStep.hs │ │ │ │ ├── SmallStep │ │ │ │ │ ├── Lazy.hs │ │ │ │ │ └── Strict.hs │ │ │ │ ├── Value.hs │ │ │ │ └── Value │ │ │ │ │ ├── Lazy.hs │ │ │ │ │ └── Strict.hs │ │ │ ├── Gen.hs │ │ │ ├── Infer.hs │ │ │ ├── Parse.hs │ │ │ └── Pretty.hs │ │ ├── Type.hs │ │ └── Type │ │ │ ├── Error.hs │ │ │ ├── Error │ │ │ ├── Gen.hs │ │ │ └── Pretty.hs │ │ │ ├── Gen.hs │ │ │ ├── Parse.hs │ │ │ └── Pretty.hs │ ├── stack.yaml │ └── tests │ │ ├── Test.hs │ │ ├── Test │ │ ├── .DS_Store │ │ ├── Term.hs │ │ ├── Term │ │ │ ├── Eval.hs │ │ │ ├── Eval │ │ │ │ ├── Lazy.hs │ │ │ │ └── Strict.hs │ │ │ ├── Infer.hs │ │ │ ├── Structure.hs │ │ │ └── Text.hs │ │ ├── Type.hs │ │ └── Type │ │ │ └── Text.hs │ │ └── doctests.hs └── old │ ├── modular │ ├── b-lang │ │ ├── LICENSE │ │ ├── Setup.hs │ │ ├── b-lang.cabal │ │ ├── default.nix │ │ ├── shell.nix │ │ └── src │ │ │ └── Component │ │ │ ├── Bool.hs │ │ │ ├── Term │ │ │ ├── Bool.hs │ │ │ └── Bool │ │ │ │ ├── Eval │ │ │ │ ├── BigStep.hs │ │ │ │ ├── SmallStep.hs │ │ │ │ ├── Value.hs │ │ │ │ └── Values.hs │ │ │ │ ├── Gen.hs │ │ │ │ ├── Infer.hs │ │ │ │ ├── Parse.hs │ │ │ │ ├── Pretty.hs │ │ │ │ ├── Strip.hs │ │ │ │ └── SubTerm.hs │ │ │ └── Type │ │ │ ├── Bool.hs │ │ │ └── Bool │ │ │ ├── Gen.hs │ │ │ ├── Parse.hs │ │ │ ├── Pretty.hs │ │ │ └── Strip.hs │ ├── cabal.project │ ├── common-lang │ │ ├── LICENSE │ │ ├── Setup.hs │ │ ├── common-lang.cabal │ │ ├── default.nix │ │ ├── result │ │ ├── shell.nix │ │ └── src │ │ │ ├── Bifunctor2.hs │ │ │ ├── Bound2.hs │ │ │ ├── Common │ │ │ ├── Note.hs │ │ │ ├── Parse.hs │ │ │ ├── Pretty.hs │ │ │ └── Text.hs │ │ │ ├── Component.hs │ │ │ ├── Component │ │ │ ├── Note.hs │ │ │ ├── Term.hs │ │ │ ├── Term │ │ │ │ ├── Eval │ │ │ │ │ ├── BigStep.hs │ │ │ │ │ ├── SmallStep.hs │ │ │ │ │ └── Value.hs │ │ │ │ ├── Gen.hs │ │ │ │ ├── Infer.hs │ │ │ │ ├── Note.hs │ │ │ │ ├── Note │ │ │ │ │ ├── Eval │ │ │ │ │ │ ├── BigStep.hs │ │ │ │ │ │ ├── SmallStep.hs │ │ │ │ │ │ └── Value.hs │ │ │ │ │ ├── Gen.hs │ │ │ │ │ ├── Infer.hs │ │ │ │ │ ├── Parse.hs │ │ │ │ │ ├── Pretty.hs │ │ │ │ │ ├── Strip.hs │ │ │ │ │ └── SubTerm.hs │ │ │ │ ├── Parse.hs │ │ │ │ ├── Pretty.hs │ │ │ │ └── SubTerm.hs │ │ │ ├── Type.hs │ │ │ └── Type │ │ │ │ ├── Error.hs │ │ │ │ ├── Error │ │ │ │ ├── ExpectedEq.hs │ │ │ │ ├── ExpectedEq │ │ │ │ │ └── Class.hs │ │ │ │ ├── Pretty.hs │ │ │ │ ├── Unexpected.hs │ │ │ │ ├── Unexpected │ │ │ │ │ └── Class.hs │ │ │ │ ├── UnknownType.hs │ │ │ │ └── UnknownType │ │ │ │ │ └── Class.hs │ │ │ │ ├── Gen.hs │ │ │ │ ├── Note.hs │ │ │ │ ├── Note │ │ │ │ ├── Gen.hs │ │ │ │ ├── Parse.hs │ │ │ │ ├── Pretty.hs │ │ │ │ └── Strip.hs │ │ │ │ ├── Parse.hs │ │ │ │ └── Pretty.hs │ │ │ ├── Extras.hs │ │ │ ├── Forall.hs │ │ │ ├── Language.hs │ │ │ ├── Repl.hs │ │ │ ├── Tests.hs │ │ │ └── Tests │ │ │ ├── Term.hs │ │ │ ├── Term │ │ │ ├── Eval.hs │ │ │ ├── Infer.hs │ │ │ └── Text.hs │ │ │ ├── Type.hs │ │ │ └── Type │ │ │ └── Text.hs │ ├── i-lang │ │ ├── LICENSE │ │ ├── Setup.hs │ │ ├── i-lang.cabal │ │ └── src │ │ │ └── Component │ │ │ ├── Int.hs │ │ │ ├── Term │ │ │ ├── Int.hs │ │ │ └── Int │ │ │ │ ├── Eval │ │ │ │ ├── BigStep.hs │ │ │ │ ├── SmallStep.hs │ │ │ │ ├── Value.hs │ │ │ │ └── Values.hs │ │ │ │ ├── Gen.hs │ │ │ │ ├── Infer.hs │ │ │ │ ├── Parse.hs │ │ │ │ ├── Pretty.hs │ │ │ │ └── SubTerm.hs │ │ │ └── Type │ │ │ ├── Int.hs │ │ │ └── Int │ │ │ ├── Gen.hs │ │ │ ├── Parse.hs │ │ │ └── Pretty.hs │ ├── n-lang │ │ ├── LICENSE │ │ ├── Setup.hs │ │ ├── n-lang.cabal │ │ └── src │ │ │ └── Component │ │ │ ├── Nat.hs │ │ │ ├── Term │ │ │ ├── Nat.hs │ │ │ └── Nat │ │ │ │ ├── Eval │ │ │ │ ├── BigStep.hs │ │ │ │ ├── SmallStep.hs │ │ │ │ ├── Value.hs │ │ │ │ └── Values.hs │ │ │ │ ├── Gen.hs │ │ │ │ ├── Infer.hs │ │ │ │ ├── Parse.hs │ │ │ │ ├── Pretty.hs │ │ │ │ └── SubTerm.hs │ │ │ └── Type │ │ │ ├── Nat.hs │ │ │ └── Nat │ │ │ ├── Gen.hs │ │ │ ├── Parse.hs │ │ │ └── Pretty.hs │ ├── nb-lang │ │ ├── LICENSE │ │ ├── Setup.hs │ │ ├── nb-lang.cabal │ │ └── src │ │ │ └── Component │ │ │ ├── NatBool.hs │ │ │ └── Term │ │ │ ├── NatBool.hs │ │ │ └── NatBool │ │ │ ├── Eval │ │ │ ├── BigStep.hs │ │ │ ├── SmallStep.hs │ │ │ ├── Value.hs │ │ │ └── Values.hs │ │ │ ├── Gen.hs │ │ │ ├── Infer.hs │ │ │ ├── Parse.hs │ │ │ ├── Pretty.hs │ │ │ └── SubTerm.hs │ ├── old-nix-config │ ├── stlc-lang │ │ ├── LICENSE │ │ ├── Setup.hs │ │ ├── projectile │ │ ├── src │ │ │ └── Component │ │ │ │ ├── STLC.hs │ │ │ │ ├── Term │ │ │ │ ├── STLC.hs │ │ │ │ └── STLC │ │ │ │ │ ├── Eval │ │ │ │ │ ├── BigStep.hs │ │ │ │ │ ├── SmallStep.hs │ │ │ │ │ └── Value.hs │ │ │ │ │ ├── Infer.hs │ │ │ │ │ ├── Parse.hs │ │ │ │ │ ├── Pretty.hs │ │ │ │ │ └── SubTerm.hs │ │ │ │ └── Type │ │ │ │ ├── Error │ │ │ │ ├── FreeVar.hs │ │ │ │ └── NotArrow.hs │ │ │ │ ├── STLC.hs │ │ │ │ └── STLC │ │ │ │ ├── Parse.hs │ │ │ │ └── Pretty.hs │ │ └── stlc-lang.cabal │ ├── test-i-lang │ │ ├── LICENSE │ │ ├── Setup.hs │ │ ├── repl │ │ │ └── Main.hs │ │ ├── src │ │ │ └── TestLanguage.hs │ │ ├── test-i-lang.cabal │ │ └── tests │ │ │ └── Test.hs │ └── test-lang │ │ ├── LICENSE │ │ ├── Setup.hs │ │ ├── repl │ │ └── Main.hs │ │ ├── src │ │ └── TestLanguage.hs │ │ ├── test-lang.cabal │ │ └── tests │ │ └── Test.hs │ ├── multityped │ ├── TODO.md │ ├── ll-util │ │ ├── LICENSE │ │ ├── Setup.hs │ │ ├── default.nix │ │ ├── ll-util.cabal │ │ ├── shell.nix │ │ └── src │ │ │ ├── Cofree1.hs │ │ │ ├── ExpressionPrinter.hs │ │ │ ├── Fix1.hs │ │ │ ├── Parse.hs │ │ │ └── Pretty.hs │ ├── nb-modular │ │ ├── LICENSE │ │ ├── Setup.hs │ │ ├── default.nix │ │ ├── nb-modular.cabal │ │ ├── repl │ │ │ └── Main.hs │ │ ├── shell.nix │ │ ├── src │ │ │ ├── Common.hs │ │ │ ├── Common │ │ │ │ ├── Error │ │ │ │ ├── Error.hs │ │ │ │ ├── Gen.hs │ │ │ │ ├── Note.hs │ │ │ │ ├── Recursion.hs │ │ │ │ ├── Repl.hs │ │ │ │ ├── Term.hs │ │ │ │ ├── Term │ │ │ │ │ ├── Eval.hs │ │ │ │ │ ├── Eval │ │ │ │ │ │ ├── BigStep.hs │ │ │ │ │ │ ├── SmallStep.hs │ │ │ │ │ │ └── Value.hs │ │ │ │ │ ├── Gen.hs │ │ │ │ │ ├── Infer.hs │ │ │ │ │ ├── Parse.hs │ │ │ │ │ ├── Pretty.hs │ │ │ │ │ └── Size.hs │ │ │ │ ├── Test.hs │ │ │ │ ├── Test │ │ │ │ │ ├── Term.hs │ │ │ │ │ ├── Term │ │ │ │ │ │ ├── Eval.hs │ │ │ │ │ │ ├── Infer.hs │ │ │ │ │ │ └── Text.hs │ │ │ │ │ ├── Type.hs │ │ │ │ │ └── Type │ │ │ │ │ │ └── Text.hs │ │ │ │ ├── Type.hs │ │ │ │ └── Type │ │ │ │ │ ├── Error.hs │ │ │ │ │ ├── Error │ │ │ │ │ └── Pretty.hs │ │ │ │ │ ├── Gen.hs │ │ │ │ │ ├── Parse.hs │ │ │ │ │ └── Pretty.hs │ │ │ ├── Components │ │ │ │ ├── Term │ │ │ │ │ ├── Bool.hs │ │ │ │ │ ├── Bool │ │ │ │ │ │ ├── Data.hs │ │ │ │ │ │ ├── Eval │ │ │ │ │ │ │ ├── BigStep.hs │ │ │ │ │ │ │ ├── SmallStep.hs │ │ │ │ │ │ │ └── Value.hs │ │ │ │ │ │ ├── Gen.hs │ │ │ │ │ │ ├── Infer.hs │ │ │ │ │ │ ├── Parse.hs │ │ │ │ │ │ └── Pretty.hs │ │ │ │ │ ├── Nat.hs │ │ │ │ │ ├── Nat │ │ │ │ │ │ ├── Data.hs │ │ │ │ │ │ ├── Eval │ │ │ │ │ │ │ ├── BigStep.hs │ │ │ │ │ │ │ ├── SmallStep.hs │ │ │ │ │ │ │ └── Value.hs │ │ │ │ │ │ ├── Gen.hs │ │ │ │ │ │ ├── Infer.hs │ │ │ │ │ │ ├── Parse.hs │ │ │ │ │ │ └── Pretty.hs │ │ │ │ │ ├── NatBool.hs │ │ │ │ │ ├── NatBool │ │ │ │ │ │ ├── Data.hs │ │ │ │ │ │ ├── Eval │ │ │ │ │ │ │ ├── BigStep.hs │ │ │ │ │ │ │ ├── SmallStep.hs │ │ │ │ │ │ │ └── Value.hs │ │ │ │ │ │ ├── Gen.hs │ │ │ │ │ │ ├── Infer.hs │ │ │ │ │ │ ├── Parse.hs │ │ │ │ │ │ └── Pretty.hs │ │ │ │ │ ├── Note.hs │ │ │ │ │ └── Note │ │ │ │ │ │ ├── Data.hs │ │ │ │ │ │ ├── Eval │ │ │ │ │ │ ├── BigStep.hs │ │ │ │ │ │ ├── SmallStep.hs │ │ │ │ │ │ └── Value.hs │ │ │ │ │ │ ├── Gen.hs │ │ │ │ │ │ ├── Infer.hs │ │ │ │ │ │ ├── Parse.hs │ │ │ │ │ │ └── Pretty.hs │ │ │ │ └── Type │ │ │ │ │ ├── Bool.hs │ │ │ │ │ ├── Bool │ │ │ │ │ ├── Data.hs │ │ │ │ │ ├── Gen.hs │ │ │ │ │ ├── Parse.hs │ │ │ │ │ └── Pretty.hs │ │ │ │ │ ├── Nat.hs │ │ │ │ │ ├── Nat │ │ │ │ │ ├── Data.hs │ │ │ │ │ ├── Gen.hs │ │ │ │ │ ├── Parse.hs │ │ │ │ │ └── Pretty.hs │ │ │ │ │ ├── Note.hs │ │ │ │ │ └── Note │ │ │ │ │ ├── Data.hs │ │ │ │ │ ├── Gen.hs │ │ │ │ │ ├── Parse.hs │ │ │ │ │ └── Pretty.hs │ │ │ └── Language │ │ │ │ ├── NB.hs │ │ │ │ └── NB │ │ │ │ ├── Term.hs │ │ │ │ ├── Type.hs │ │ │ │ └── Type │ │ │ │ └── Error.hs │ │ └── tests │ │ │ ├── Test.hs │ │ │ └── Test │ │ │ ├── Term.hs │ │ │ ├── Term │ │ │ ├── Eval.hs │ │ │ └── Text.hs │ │ │ ├── Type.hs │ │ │ └── Type │ │ │ ├── Infer.hs │ │ │ ├── Safety.hs │ │ │ └── Text.hs │ ├── nb-srcloc │ │ ├── LICENSE │ │ ├── Setup.hs │ │ ├── default.nix │ │ ├── nb-srcloc.cabal │ │ ├── repl │ │ │ └── Main.hs │ │ ├── shell.nix │ │ ├── src │ │ │ ├── Loc.hs │ │ │ ├── Term.hs │ │ │ ├── Term │ │ │ │ ├── Eval │ │ │ │ │ ├── BigStep.hs │ │ │ │ │ ├── SmallStep.hs │ │ │ │ │ └── Value.hs │ │ │ │ ├── Gen.hs │ │ │ │ ├── Infer.hs │ │ │ │ ├── Parse.hs │ │ │ │ └── Pretty.hs │ │ │ ├── Type.hs │ │ │ ├── Type │ │ │ │ ├── Error.hs │ │ │ │ ├── Error │ │ │ │ │ ├── Message.hs │ │ │ │ │ └── Pretty.hs │ │ │ │ ├── Gen.hs │ │ │ │ ├── Infer.hs │ │ │ │ ├── Parse.hs │ │ │ │ └── Pretty.hs │ │ │ └── UI.hs │ │ └── tests │ │ │ ├── Test.hs │ │ │ └── Test │ │ │ ├── Term.hs │ │ │ ├── Term │ │ │ ├── Eval.hs │ │ │ ├── Infer.hs │ │ │ └── Text.hs │ │ │ ├── Type.hs │ │ │ └── Type │ │ │ ├── Infer.hs │ │ │ ├── Safety.hs │ │ │ └── Text.hs │ ├── nb │ │ ├── LICENSE │ │ ├── Setup.hs │ │ ├── default.nix │ │ ├── nb.cabal │ │ ├── repl │ │ │ └── Main.hs │ │ ├── shell.nix │ │ ├── src │ │ │ ├── Term.hs │ │ │ ├── Term │ │ │ │ ├── Eval │ │ │ │ │ ├── BigStep.hs │ │ │ │ │ ├── SmallStep.hs │ │ │ │ │ └── Value.hs │ │ │ │ ├── Gen.hs │ │ │ │ ├── Infer.hs │ │ │ │ ├── Parse.hs │ │ │ │ └── Pretty.hs │ │ │ ├── Type.hs │ │ │ ├── Type │ │ │ │ ├── Error.hs │ │ │ │ ├── Error │ │ │ │ │ ├── Gen.hs │ │ │ │ │ └── Pretty.hs │ │ │ │ ├── Gen.hs │ │ │ │ ├── Infer.hs │ │ │ │ ├── Parse.hs │ │ │ │ └── Pretty.hs │ │ │ └── UI.hs │ │ └── tests │ │ │ ├── Test.hs │ │ │ └── Test │ │ │ ├── Term.hs │ │ │ ├── Term │ │ │ ├── Eval.hs │ │ │ ├── Infer.hs │ │ │ └── Text.hs │ │ │ ├── Type.hs │ │ │ └── Type │ │ │ ├── Infer.hs │ │ │ ├── Safety.hs │ │ │ └── Text.hs │ ├── old-stlc-b │ │ ├── LICENSE │ │ ├── Setup.hs │ │ ├── default.nix │ │ ├── shell.nix │ │ ├── src │ │ │ ├── Term.hs │ │ │ ├── Term │ │ │ │ ├── Eval │ │ │ │ │ ├── BigStep.hs │ │ │ │ │ ├── SmallStep.hs │ │ │ │ │ └── Value.hs │ │ │ │ ├── Gen.hs │ │ │ │ ├── Parse.hs │ │ │ │ └── Pretty.hs │ │ │ ├── Type.hs │ │ │ ├── Type │ │ │ │ ├── Error.hs │ │ │ │ ├── Error │ │ │ │ │ └── Message.hs │ │ │ │ ├── Gen.hs │ │ │ │ ├── Infer.hs │ │ │ │ ├── Parse.hs │ │ │ │ └── Pretty.hs │ │ │ ├── UI.hs │ │ │ └── Util │ │ │ │ └── Types.hs │ │ ├── stlc-b.cabal │ │ └── tests │ │ │ └── Test.hs │ └── stlc-b │ │ ├── LICENSE │ │ ├── Setup.hs │ │ ├── default.nix │ │ ├── repl │ │ └── Main.hs │ │ ├── shell.nix │ │ ├── src │ │ ├── Loc.hs │ │ ├── Term.hs │ │ ├── Term │ │ │ ├── Eval │ │ │ │ ├── BigStep.hs │ │ │ │ ├── SmallStep.hs │ │ │ │ └── Value.hs │ │ │ ├── Gen.hs │ │ │ ├── Parse.hs │ │ │ └── Pretty.hs │ │ ├── Type.hs │ │ ├── Type │ │ │ ├── Error.hs │ │ │ ├── Error │ │ │ │ └── Message.hs │ │ │ ├── Gen.hs │ │ │ ├── Infer.hs │ │ │ ├── Parse.hs │ │ │ └── Pretty.hs │ │ └── UI.hs │ │ ├── stlc-b.cabal │ │ └── tests │ │ ├── Test.hs │ │ └── Test │ │ ├── Term.hs │ │ ├── Term │ │ ├── Eval.hs │ │ └── Text.hs │ │ ├── Type.hs │ │ └── Type │ │ ├── Infer.hs │ │ ├── Safety.hs │ │ └── Text.hs │ ├── prototypes │ ├── ann │ │ └── src │ │ │ └── Term.hs │ ├── arith │ │ ├── LICENSE │ │ ├── Setup.hs │ │ ├── arith.cabal │ │ ├── default.nix │ │ ├── shell.nix │ │ └── src │ │ │ ├── Arith.hs │ │ │ ├── Rules.hs │ │ │ ├── STLC.hs │ │ │ └── STLC │ │ │ ├── Check.hs │ │ │ ├── Classy.hs │ │ │ ├── Eval.hs │ │ │ ├── Tag.hs │ │ │ └── Type.hs │ ├── bits │ │ ├── LICENSE │ │ ├── Setup.hs │ │ ├── bits.cabal │ │ ├── default.nix │ │ ├── shell.nix │ │ └── src │ │ │ ├── Bits.hs │ │ │ └── Coproduct.hs │ ├── classy │ │ ├── LICENSE │ │ ├── Setup.hs │ │ ├── classy.cabal │ │ ├── default.nix │ │ ├── shell.nix │ │ └── src │ │ │ ├── Rules.hs │ │ │ ├── Rules │ │ │ ├── Div.hs │ │ │ ├── GenShrink.hs │ │ │ ├── GenShrink │ │ │ │ └── Test.hs │ │ │ ├── Json.hs │ │ │ ├── Match.hs │ │ │ └── Pattern.hs │ │ │ ├── STLC │ │ │ ├── Syntax │ │ │ │ ├── Bool.hs │ │ │ │ ├── Eq.hs │ │ │ │ ├── Int.hs │ │ │ │ ├── LC.hs │ │ │ │ ├── Logic.hs │ │ │ │ ├── Num.hs │ │ │ │ └── Ord.hs │ │ │ └── Type.hs │ │ │ ├── Term │ │ │ ├── Component │ │ │ │ ├── Bool.hs │ │ │ │ ├── Eq.hs │ │ │ │ ├── Int.hs │ │ │ │ ├── LC.hs │ │ │ │ ├── Logic.hs │ │ │ │ ├── Num.hs │ │ │ │ └── Ord.hs │ │ │ ├── Eval.hs │ │ │ └── Value.hs │ │ │ └── Type │ │ │ ├── Check.hs │ │ │ └── Component │ │ │ ├── Arrow.hs │ │ │ ├── Bool.hs │ │ │ └── Int.hs │ ├── data-decl │ │ └── src │ │ │ ├── Check.hs │ │ │ ├── Term.hs │ │ │ └── Type.hs │ ├── frag │ │ ├── LICENSE │ │ ├── Setup.hs │ │ ├── default.nix │ │ ├── frag.cabal │ │ ├── shell.nix │ │ └── src │ │ │ ├── Term.hs │ │ │ ├── TermF.hs │ │ │ └── TermL.hs │ ├── lc-full │ │ ├── LICENSE │ │ ├── Setup.hs │ │ ├── default.nix │ │ ├── lc-full.cabal │ │ ├── shell.nix │ │ └── src │ │ │ └── Term.hs │ ├── lc-named │ │ ├── LICENSE │ │ ├── Setup.hs │ │ ├── default.nix │ │ ├── lc-named.cabal │ │ ├── shell.nix │ │ └── src │ │ │ └── Term │ │ │ └── AST.hs │ ├── lc │ │ ├── LICENSE │ │ ├── Setup.hs │ │ ├── default.nix │ │ ├── lc.cabal │ │ ├── shell.nix │ │ └── src │ │ │ └── Term │ │ │ ├── AST.hs │ │ │ └── Pretty.hs │ ├── little │ │ ├── LICENSE │ │ ├── Setup.hs │ │ ├── default.nix │ │ ├── little.cabal │ │ ├── shell.nix │ │ └── src │ │ │ └── Term.hs │ ├── locs │ │ └── src │ │ │ ├── Term.hs │ │ │ └── TermL.hs │ ├── nb │ │ ├── LICENSE │ │ ├── Setup.hs │ │ ├── default.nix │ │ ├── nb.cabal │ │ ├── shell.nix │ │ └── src │ │ │ ├── IB.hs │ │ │ ├── Math.hs │ │ │ ├── NB.hs │ │ │ └── STLC.hs │ ├── proap │ │ ├── LICENSE │ │ ├── LICENSE.save0 │ │ ├── Setup.hs │ │ ├── Setup.hs.save0 │ │ ├── Setup.hs.save1 │ │ ├── default.nix │ │ ├── proap.cabal │ │ ├── proap.cabal.save0 │ │ ├── proap.cabal.save1 │ │ ├── shell.nix │ │ └── src │ │ │ ├── Div.hs │ │ │ ├── GenShrink.hs │ │ │ └── GenShrink │ │ │ └── Test.hs │ ├── prod │ │ ├── LICENSE │ │ ├── Setup.hs │ │ ├── default.nix │ │ ├── prod.cabal │ │ ├── shell.nix │ │ └── src │ │ │ ├── Data.hs │ │ │ ├── Decl.hs │ │ │ ├── Term.hs │ │ │ ├── Term_flymake.hs │ │ │ ├── Type.hs │ │ │ └── TypeCheck.hs │ ├── syntax │ │ ├── LICENSE │ │ ├── Setup.hs │ │ ├── default.nix │ │ ├── shell.nix │ │ ├── src │ │ │ ├── Term.hs │ │ │ └── Term │ │ │ │ ├── Parser.hs │ │ │ │ └── Pretty.hs │ │ └── syntax.cabal │ └── type │ │ ├── LICENSE │ │ ├── Setup.hs │ │ ├── default.nix │ │ ├── shell.nix │ │ ├── src │ │ ├── Term.hs │ │ ├── Type.hs │ │ └── TypeCheck.hs │ │ └── type.cabal │ └── unityped │ ├── b │ ├── LICENSE │ ├── Setup.hs │ ├── b.cabal │ ├── default.nix │ ├── repl │ │ └── Main.hs │ ├── shell.nix │ ├── src │ │ ├── Term.hs │ │ ├── Term │ │ │ ├── Eval │ │ │ │ ├── BigStep.hs │ │ │ │ ├── SmallStep.hs │ │ │ │ └── Value.hs │ │ │ ├── Gen.hs │ │ │ ├── Parse.hs │ │ │ └── Pretty.hs │ │ └── UI.hs │ └── tests │ │ ├── Test.hs │ │ └── Test │ │ ├── Term.hs │ │ └── Term │ │ ├── Eval.hs │ │ └── Text.hs │ ├── i │ ├── LICENSE │ ├── Setup.hs │ ├── default.nix │ ├── i.cabal │ ├── repl │ │ └── Main.hs │ ├── shell.nix │ ├── src │ │ ├── Term.hs │ │ ├── Term │ │ │ ├── Eval │ │ │ │ ├── BigStep.hs │ │ │ │ ├── SmallStep.hs │ │ │ │ └── Value.hs │ │ │ ├── Gen.hs │ │ │ ├── Parse.hs │ │ │ └── Pretty.hs │ │ └── UI.hs │ └── tests │ │ ├── Test.hs │ │ └── Test │ │ ├── Term.hs │ │ └── Term │ │ ├── Eval.hs │ │ └── Text.hs │ ├── lc │ ├── LICENSE │ ├── Setup.hs │ ├── default.nix │ ├── lc.cabal │ ├── repl │ │ └── Main.hs │ ├── shell.nix │ ├── src │ │ ├── Term.hs │ │ ├── Term │ │ │ ├── Eval │ │ │ │ ├── BigStep.hs │ │ │ │ ├── SmallStep.hs │ │ │ │ └── Value.hs │ │ │ ├── Gen.hs │ │ │ ├── Parse.hs │ │ │ └── Pretty.hs │ │ └── UI.hs │ └── tests │ │ ├── Test.hs │ │ └── Test │ │ ├── Term.hs │ │ └── Term │ │ ├── Eval.hs │ │ └── Text.hs │ └── n │ ├── LICENSE │ ├── Setup.hs │ ├── default.nix │ ├── n.cabal │ ├── repl │ └── Main.hs │ ├── shell.nix │ ├── src │ ├── Term.hs │ ├── Term │ │ ├── Eval │ │ │ ├── BigStep.hs │ │ │ ├── SmallStep.hs │ │ │ └── Value.hs │ │ ├── Gen.hs │ │ ├── Parse.hs │ │ └── Pretty.hs │ └── UI.hs │ └── tests │ ├── Test.hs │ └── Test │ ├── Term.hs │ └── Term │ ├── Eval.hs │ └── Text.hs └── talks └── ylj16 ├── .gitignore ├── big-slides.tex ├── build.sh ├── little-slides.tex ├── slides.pdf └── slides.tex /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | TAGS 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This is the code, slides and blog posts for my [little languages](http://dlaing.org/little-languages) series. 2 | -------------------------------------------------------------------------------- /blog/.gitignore: -------------------------------------------------------------------------------- 1 | .cabal-sandbox 2 | cabal.sandbox.config 3 | dist 4 | _site 5 | _cache 6 | deploy 7 | -------------------------------------------------------------------------------- /blog/css/custom.css: -------------------------------------------------------------------------------- 1 | code { 2 | color: #2352C7; 3 | background-color: #F5F5F5; 4 | } 5 | -------------------------------------------------------------------------------- /blog/css/syntax.css: -------------------------------------------------------------------------------- 1 | /* Generated by pandoc. */ 2 | table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode, table.sourceCode pre 3 | { margin: 0; padding: 0; border: 0; vertical-align: baseline; border: none; } 4 | td.lineNumbers { border-right: 1px solid #AAAAAA; text-align: right; color: #AAAAAA; padding-right: 5px; padding-left: 5px; } 5 | td.sourceCode { padding-left: 5px; } 6 | .sourceCode span.kw { color: #007020; font-weight: bold; } 7 | .sourceCode span.dt { color: #902000; } 8 | .sourceCode span.dv { color: #40a070; } 9 | .sourceCode span.bn { color: #40a070; } 10 | .sourceCode span.fl { color: #40a070; } 11 | .sourceCode span.ch { color: #4070a0; } 12 | .sourceCode span.st { color: #4070a0; } 13 | .sourceCode span.co { color: #60a0b0; font-style: italic; } 14 | .sourceCode span.ot { color: #007020; } 15 | .sourceCode span.al { color: red; font-weight: bold; } 16 | .sourceCode span.fu { color: #06287e; } 17 | .sourceCode span.re { } 18 | .sourceCode span.er { color: red; font-weight: bold; } 19 | -------------------------------------------------------------------------------- /blog/deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cp -r _site/* deploy/ 3 | pushd deploy 4 | git add --all 5 | git commit -m "snapshot $(date '+%y-%m-%d %H:%M')" 6 | git push origin gh-pages 7 | popd 8 | -------------------------------------------------------------------------------- /blog/drafts/nb/srclocs.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: NB - tracking source locations 3 | published: 2016-05-27 12:00:00+10:00 4 | --- 5 | 6 | [Previously](types.html) 7 | 8 | # Trifecta and source locations 9 | 10 | # Annotating the terms 11 | 12 | TODO mention various options in passing 13 | TODO mention that we have an optional annotation as one reason, and that we have something up our sleeve for later as the other reason 14 | 15 | # Updating the existing code 16 | 17 | ## From the parser to the terms 18 | 19 | ## From the terms to the types 20 | 21 | ## From the types to the pretty printer 22 | 23 | ## Updating the tests? 24 | 25 | involves parsing, then making sure that each of the subterms can be parsed with the snippet of text at it's source location 26 | 27 | ## Updating the REPL 28 | -------------------------------------------------------------------------------- /blog/drafts/nb/testing.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Testing NB 3 | published: 2016-05-27 12:00:00+10:00 4 | --- 5 | 6 | # A new suite of generators 7 | 8 | ## Well typed terms 9 | 10 | ## Ill typed terms 11 | 12 | ## Terms containing other terms 13 | 14 | # Writing the properties 15 | 16 | ## Progress 17 | 18 | ## Preservation 19 | 20 | ## Double-checking our generators 21 | 22 | This should have given a boost to our confidence in *NB*. 23 | 24 | As usual, we should try some things out in the REPL. 25 | 26 | TODO going right 27 | TODO type errors, and their horribleness 28 | TODO link to page on srclocs 29 | 30 | # Exercises for the adventurous 31 | -------------------------------------------------------------------------------- /blog/little-languages-blog.cabal: -------------------------------------------------------------------------------- 1 | name: little-languages-blog 2 | version: 0.1.0.0 3 | build-type: Simple 4 | cabal-version: >= 1.10 5 | 6 | executable site 7 | main-is: site.hs 8 | build-depends: base == 4.* 9 | , hakyll == 4.8.* 10 | , latex-formulae-image 11 | , latex-formulae-pandoc 12 | , latex-formulae-hakyll 13 | ghc-options: -threaded 14 | default-language: Haskell2010 15 | -------------------------------------------------------------------------------- /blog/templates/index.html: -------------------------------------------------------------------------------- 1 | $body$ 2 | -------------------------------------------------------------------------------- /blog/templates/post-list.html: -------------------------------------------------------------------------------- 1 | 2 | $for(posts)$ 3 | 4 | 5 | 6 | 7 | $endfor$ 8 |
$title$$date$
9 | -------------------------------------------------------------------------------- /blog/templates/post.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |

$title$

4 |
5 |
6 | $body$ 7 |
8 | $if(date)$ 9 | 12 | $endif$ 13 |
14 | -------------------------------------------------------------------------------- /code/.gitignore: -------------------------------------------------------------------------------- 1 | dist 2 | cabal.sandbox.config 3 | sandbox 4 | TAGS 5 | *.tix 6 | .projectile 7 | .stack-work 8 | dist-newstyle 9 | cabal.project.local 10 | 11 | -------------------------------------------------------------------------------- /code/b/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dalaing/little-languages/9f089f646a5344b8f7178700455a36a755d29b1f/code/b/.DS_Store -------------------------------------------------------------------------------- /code/b/.gitignore: -------------------------------------------------------------------------------- 1 | images 2 | -------------------------------------------------------------------------------- /code/b/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /code/b/default.nix: -------------------------------------------------------------------------------- 1 | { mkDerivation, ansi-wl-pprint, base, doctest, doctest-discover 2 | , haskeline, mtl, parsers, QuickCheck, stdenv, tasty 3 | , tasty-quickcheck, transformers, trifecta, unordered-containers 4 | }: 5 | mkDerivation { 6 | pname = "b"; 7 | version = "0.1.0.0"; 8 | src = ./.; 9 | isLibrary = true; 10 | isExecutable = true; 11 | libraryHaskellDepends = [ 12 | ansi-wl-pprint base mtl parsers QuickCheck trifecta 13 | unordered-containers 14 | ]; 15 | executableHaskellDepends = [ 16 | ansi-wl-pprint base haskeline transformers 17 | ]; 18 | testHaskellDepends = [ 19 | base doctest doctest-discover QuickCheck tasty tasty-quickcheck 20 | ]; 21 | license = stdenv.lib.licenses.bsd3; 22 | } 23 | -------------------------------------------------------------------------------- /code/b/shell.nix: -------------------------------------------------------------------------------- 1 | with (import {}).pkgs; 2 | let modifiedHaskellPackages = haskellPackages.override { 3 | overrides = self: super: { 4 | b-lang = self.callPackage ./. {}; 5 | }; 6 | }; 7 | in modifiedHaskellPackages.b-lang.env 8 | 9 | -------------------------------------------------------------------------------- /code/b/src/Common/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dalaing/little-languages/9f089f646a5344b8f7178700455a36a755d29b1f/code/b/src/Common/.DS_Store -------------------------------------------------------------------------------- /code/b/src/Common/Parse.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | 8 | Helpers for parsing. 9 | -} 10 | module Common.Parse ( 11 | parseFromString 12 | ) where 13 | 14 | -- from 'ansi-wl-pprint' 15 | import Text.PrettyPrint.ANSI.Leijen (Doc) 16 | 17 | -- from 'trifecta' 18 | import Text.Trifecta.Delta (Delta (..)) 19 | import Text.Trifecta.Parser (Parser, parseString) 20 | import Text.Trifecta.Result (Result (..)) 21 | 22 | -- | Runs a 'Parser' over a string and converts the result to an 'Either'. 23 | parseFromString :: Parser a 24 | -> String 25 | -> Either Doc a 26 | parseFromString p s = 27 | case parseString p (Columns 0 0) s of 28 | Success r -> Right r 29 | Failure d -> Left d 30 | -------------------------------------------------------------------------------- /code/b/src/Type.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | 8 | Types for the B language. 9 | -} 10 | module Type ( 11 | Type(..) 12 | ) where 13 | 14 | -- | The types in the B language. 15 | data Type = 16 | TyBool -- ^ The type of Booleans. 17 | deriving (Eq, Ord, Show) 18 | -------------------------------------------------------------------------------- /code/b/src/Type/Gen.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | 8 | Generators for types of the B language. 9 | -} 10 | module Type.Gen ( 11 | genType 12 | , shrinkType 13 | , AnyType(..) 14 | ) where 15 | 16 | -- from 'QuickCheck' 17 | import Test.QuickCheck (Gen, Arbitrary(..)) 18 | 19 | -- local 20 | import Type (Type (..)) 21 | 22 | -- | Generates types of the B language. 23 | genType :: Gen Type 24 | genType = 25 | pure TyBool 26 | 27 | -- | Shrinks types of the B language. 28 | shrinkType :: Type 29 | -> [Type] 30 | shrinkType _ = 31 | [] 32 | 33 | -- | A newtype wrapper for generating types of the B language. 34 | newtype AnyType = AnyType { 35 | getAnyType :: Type 36 | } deriving (Eq, Show) 37 | 38 | instance Arbitrary AnyType where 39 | arbitrary = 40 | fmap AnyType genType 41 | shrink = 42 | fmap AnyType . shrinkType . getAnyType 43 | -------------------------------------------------------------------------------- /code/b/tests/Test.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Main ( 9 | main 10 | ) where 11 | 12 | -- from 'tasty' 13 | import Test.Tasty (TestTree, defaultMain, testGroup) 14 | 15 | -- local 16 | import Test.Term (termTests) 17 | import Test.Type (typeTests) 18 | 19 | main :: IO () 20 | main = defaultMain tests 21 | 22 | tests :: TestTree 23 | tests = testGroup "tests" 24 | [ typeTests 25 | , termTests 26 | ] 27 | 28 | -------------------------------------------------------------------------------- /code/b/tests/Test/Term.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Test.Term ( 9 | termTests 10 | ) where 11 | 12 | -- from 'tasty' 13 | import Test.Tasty (TestTree, testGroup) 14 | 15 | -- local 16 | import Test.Term.Eval (evalTests) 17 | import Test.Term.Infer (inferTests) 18 | import Test.Term.Structure (structureTests) 19 | import Test.Term.Text (textTests) 20 | 21 | termTests :: TestTree 22 | termTests = 23 | testGroup "term" 24 | [ structureTests 25 | , evalTests 26 | , inferTests 27 | , textTests 28 | ] 29 | -------------------------------------------------------------------------------- /code/b/tests/Test/Term/Structure.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Test.Term.Structure ( 9 | structureTests 10 | ) where 11 | 12 | -- from 'tasty' 13 | import Test.Tasty (TestTree, testGroup) 14 | 15 | -- from 'tasty-quickcheck' 16 | import Test.Tasty.QuickCheck (testProperty) 17 | 18 | -- local 19 | import Term (contains, size, subTerms) 20 | import Term.Gen (AnyTerm (..)) 21 | 22 | structureTests :: TestTree 23 | structureTests = 24 | testGroup "structure" 25 | [ testProperty "subterms matches size" propSubtermsSize 26 | , testProperty "subterms matches contains" propSubtermsContains 27 | ] 28 | 29 | propSubtermsSize :: AnyTerm 30 | -> Bool 31 | propSubtermsSize (AnyTerm tm) = 32 | size tm - 1 <= length (subTerms tm) 33 | 34 | propSubtermsContains :: AnyTerm 35 | -> Bool 36 | propSubtermsContains (AnyTerm tm) = 37 | all (tm `contains`) (subTerms tm) 38 | -------------------------------------------------------------------------------- /code/b/tests/Test/Type.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Test.Type ( 9 | typeTests 10 | ) where 11 | 12 | -- from 'tasty' 13 | import Test.Tasty (TestTree, testGroup) 14 | 15 | -- local 16 | import Test.Type.Text (textTests) 17 | 18 | typeTests :: TestTree 19 | typeTests = 20 | testGroup "type" 21 | [textTests] 22 | -------------------------------------------------------------------------------- /code/b/tests/doctests.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | -- from 'doctest' 9 | import Test.DocTest 10 | 11 | main :: IO () 12 | main = doctest [ "-isrc", "src"] 13 | {- 14 | [ "Common.Parse" 15 | , "Common.Pretty" 16 | , "Term" 17 | , "Term.Eval.Value" 18 | , "Term.Eval.SmallStep" 19 | , "Term.Eval.BigStep" 20 | , "Term.Infer" 21 | , "Term.Parse" 22 | , "Term.Pretty" 23 | , "Type" 24 | , "Type.Parse" 25 | , "Type.Pretty" 26 | , "Type.Error" 27 | , "Type.Error.Pretty" 28 | ] 29 | -} 30 | 31 | -------------------------------------------------------------------------------- /code/i/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dalaing/little-languages/9f089f646a5344b8f7178700455a36a755d29b1f/code/i/.DS_Store -------------------------------------------------------------------------------- /code/i/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /code/i/default.nix: -------------------------------------------------------------------------------- 1 | { mkDerivation, ansi-wl-pprint, base, doctest, haskeline, mtl 2 | , parsers, QuickCheck, stdenv, tasty, tasty-quickcheck 3 | , transformers, trifecta, unordered-containers 4 | }: 5 | mkDerivation { 6 | pname = "i"; 7 | version = "0.1.0.0"; 8 | src = ./.; 9 | isLibrary = true; 10 | isExecutable = true; 11 | libraryHaskellDepends = [ 12 | ansi-wl-pprint base mtl parsers QuickCheck trifecta 13 | unordered-containers 14 | ]; 15 | executableHaskellDepends = [ 16 | ansi-wl-pprint base haskeline transformers 17 | ]; 18 | testHaskellDepends = [ 19 | base doctest QuickCheck tasty tasty-quickcheck 20 | ]; 21 | license = stdenv.lib.licenses.bsd3; 22 | } 23 | -------------------------------------------------------------------------------- /code/i/shell.nix: -------------------------------------------------------------------------------- 1 | with (import {}).pkgs; 2 | let modifiedHaskellPackages = haskellPackages.override { 3 | overrides = self: super: { 4 | b-lang = self.callPackage ./. {}; 5 | }; 6 | }; 7 | in modifiedHaskellPackages.b-lang.env 8 | 9 | -------------------------------------------------------------------------------- /code/i/src/Common/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dalaing/little-languages/9f089f646a5344b8f7178700455a36a755d29b1f/code/i/src/Common/.DS_Store -------------------------------------------------------------------------------- /code/i/src/Type.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | 8 | Types for the I language. 9 | -} 10 | module Type ( 11 | Type(..) 12 | ) where 13 | 14 | -- | The types in the I language. 15 | data Type = 16 | TyInt -- ^ The type of integers. 17 | deriving (Eq, Ord, Show) 18 | -------------------------------------------------------------------------------- /code/i/src/Type/Gen.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | 8 | Generators for types of the I language. 9 | -} 10 | module Type.Gen ( 11 | genType 12 | , shrinkType 13 | , AnyType(..) 14 | ) where 15 | 16 | -- from 'QuickCheck' 17 | import Test.QuickCheck (Gen, Arbitrary(..)) 18 | 19 | -- local 20 | import Type (Type (..)) 21 | 22 | -- | Generates types of the I language. 23 | genType :: Gen Type 24 | genType = 25 | pure TyInt 26 | 27 | -- | Shrinks types of the I language. 28 | shrinkType :: Type 29 | -> [Type] 30 | shrinkType _ = 31 | [] 32 | 33 | -- | A newtype wrapper for generating types of the I language. 34 | newtype AnyType = AnyType { 35 | getAnyType :: Type 36 | } deriving (Eq, Show) 37 | 38 | instance Arbitrary AnyType where 39 | arbitrary = 40 | fmap AnyType genType 41 | shrink = 42 | fmap AnyType . shrinkType . getAnyType 43 | -------------------------------------------------------------------------------- /code/i/tests/Test.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Main ( 9 | main 10 | ) where 11 | 12 | -- from 'tasty' 13 | import Test.Tasty (TestTree, defaultMain, testGroup) 14 | 15 | -- local 16 | import Test.Common (commonTests) 17 | import Test.Term (termTests) 18 | import Test.Type (typeTests) 19 | 20 | main :: IO () 21 | main = defaultMain tests 22 | 23 | tests :: TestTree 24 | tests = testGroup "tests" 25 | [ commonTests 26 | , typeTests 27 | , termTests 28 | ] 29 | 30 | -------------------------------------------------------------------------------- /code/i/tests/Test/Common.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Test.Common ( 9 | commonTests 10 | ) where 11 | 12 | -- from 'tasty' 13 | import Test.Tasty (TestTree, testGroup) 14 | 15 | -- local 16 | import Test.Common.Text (textTests) 17 | 18 | commonTests :: TestTree 19 | commonTests = 20 | testGroup "common" 21 | [textTests] 22 | -------------------------------------------------------------------------------- /code/i/tests/Test/Term.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Test.Term ( 9 | termTests 10 | ) where 11 | 12 | -- from 'tasty' 13 | import Test.Tasty (TestTree, testGroup) 14 | 15 | -- local 16 | import Test.Term.Eval (evalTests) 17 | import Test.Term.Infer (inferTests) 18 | import Test.Term.Structure (structureTests) 19 | import Test.Term.Text (textTests) 20 | 21 | termTests :: TestTree 22 | termTests = 23 | testGroup "term" 24 | [ structureTests 25 | , evalTests 26 | , inferTests 27 | , textTests 28 | ] 29 | -------------------------------------------------------------------------------- /code/i/tests/Test/Type.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Test.Type ( 9 | typeTests 10 | ) where 11 | 12 | -- from 'tasty' 13 | import Test.Tasty (TestTree, testGroup) 14 | 15 | -- local 16 | import Test.Type.Text (textTests) 17 | 18 | typeTests :: TestTree 19 | typeTests = 20 | testGroup "type" 21 | [textTests] 22 | -------------------------------------------------------------------------------- /code/i/tests/doctests.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | -- from 'doctest' 9 | import Test.DocTest 10 | 11 | main :: IO () 12 | main = doctest [ "-isrc", "src"] 13 | {- 14 | [ "Common.Parse" 15 | , "Common.Pretty" 16 | , "Term" 17 | , "Term.Eval.Value" 18 | , "Term.Eval.SmallStep" 19 | , "Term.Eval.BigStep" 20 | , "Term.Infer" 21 | , "Term.Parse" 22 | , "Term.Pretty" 23 | , "Type" 24 | , "Type.Parse" 25 | , "Type.Pretty" 26 | , "Type.Error" 27 | , "Type.Error.Pretty" 28 | ] 29 | -} 30 | 31 | -------------------------------------------------------------------------------- /code/n/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /code/n/default.nix: -------------------------------------------------------------------------------- 1 | { mkDerivation, ansi-wl-pprint, base, doctest, doctest-discover 2 | , haskeline, mtl, parsers, QuickCheck, stdenv, tasty 3 | , tasty-quickcheck, transformers, trifecta, unordered-containers 4 | }: 5 | mkDerivation { 6 | pname = "n"; 7 | version = "0.1.0.0"; 8 | src = ./.; 9 | isLibrary = true; 10 | isExecutable = true; 11 | libraryHaskellDepends = [ 12 | ansi-wl-pprint base mtl parsers QuickCheck trifecta 13 | unordered-containers 14 | ]; 15 | executableHaskellDepends = [ 16 | ansi-wl-pprint base haskeline transformers 17 | ]; 18 | testHaskellDepends = [ 19 | base doctest doctest-discover QuickCheck tasty tasty-quickcheck 20 | ]; 21 | license = stdenv.lib.licenses.bsd3; 22 | } 23 | -------------------------------------------------------------------------------- /code/n/shell.nix: -------------------------------------------------------------------------------- 1 | with (import {}).pkgs; 2 | let modifiedHaskellPackages = haskellPackages.override { 3 | overrides = self: super: { 4 | n-lang = self.callPackage ./. {}; 5 | }; 6 | }; 7 | in modifiedHaskellPackages.n-lang.env 8 | 9 | -------------------------------------------------------------------------------- /code/n/src/Common/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dalaing/little-languages/9f089f646a5344b8f7178700455a36a755d29b1f/code/n/src/Common/.DS_Store -------------------------------------------------------------------------------- /code/n/src/Common/Parse.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | 8 | Helpers for parsing. 9 | -} 10 | module Common.Parse ( 11 | parseFromString 12 | ) where 13 | 14 | -- from 'ansi-wl-pprint' 15 | import Text.PrettyPrint.ANSI.Leijen (Doc) 16 | 17 | -- from 'trifecta' 18 | import Text.Trifecta.Delta (Delta (..)) 19 | import Text.Trifecta.Parser (Parser, parseString) 20 | import Text.Trifecta.Result (Result (..)) 21 | 22 | -- | Runs a 'Parser' over a string and converts the result to an 'Either'. 23 | parseFromString :: Parser a 24 | -> String 25 | -> Either Doc a 26 | parseFromString p s = 27 | case parseString p (Columns 0 0) s of 28 | Success r -> Right r 29 | Failure d -> Left d 30 | -------------------------------------------------------------------------------- /code/n/src/Term/Eval/BigStep.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : POSIX 7 | 8 | Big step rules and helpers for the N language. 9 | 10 | This module reexports 'Term.Eval.BigStep.Strict'. 11 | There is also 'Term.Eval.BigStep.Lazy' if you need it. 12 | -} 13 | module Term.Eval.BigStep ( 14 | module Term.Eval.BigStep.Strict 15 | ) where 16 | 17 | -- local 18 | import Term.Eval.BigStep.Strict 19 | -------------------------------------------------------------------------------- /code/n/src/Term/Eval/SmallStep.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | 8 | Small-step rules and helpers for the N language. 9 | 10 | This module reexports 'Term.Eval.SmallStep.Strict'. 11 | There is also 'Term.Eval.SmallStep.Lazy' if you need it. 12 | -} 13 | module Term.Eval.SmallStep ( 14 | module Term.Eval.SmallStep.Strict 15 | ) where 16 | 17 | -- local 18 | import Term.Eval.SmallStep.Strict 19 | -------------------------------------------------------------------------------- /code/n/src/Term/Eval/Value.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | 8 | Value rules and helpers for the N language. 9 | 10 | This module reexports 'Term.Eval.Value.Strict'. 11 | There is also 'Term.Eval.Value.Lazy' if you need it. 12 | -} 13 | module Term.Eval.Value ( 14 | module Term.Eval.Value.Strict 15 | ) where 16 | 17 | -- local 18 | import Term.Eval.Value.Strict 19 | -------------------------------------------------------------------------------- /code/n/src/Type.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | 8 | Types for the N language. 9 | -} 10 | module Type ( 11 | Type(..) 12 | ) where 13 | 14 | -- | The types in the N language. 15 | data Type = 16 | TyNat -- ^ The type of natural numbers. 17 | deriving (Eq, Ord, Show) 18 | -------------------------------------------------------------------------------- /code/n/src/Type/Gen.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | 8 | Generators for types of the N language. 9 | -} 10 | module Type.Gen ( 11 | genType 12 | , shrinkType 13 | , AnyType(..) 14 | ) where 15 | 16 | -- from 'QuickCheck' 17 | import Test.QuickCheck (Gen, Arbitrary(..)) 18 | 19 | -- local 20 | import Type (Type (..)) 21 | 22 | -- | Generates types of the N language. 23 | genType :: Gen Type 24 | genType = 25 | pure TyNat 26 | 27 | -- | Shrinks types of the N language. 28 | shrinkType :: Type 29 | -> [Type] 30 | shrinkType _ = 31 | [] 32 | 33 | -- | A newtype wrapper for generating types of the N language. 34 | newtype AnyType = AnyType { 35 | getAnyType :: Type 36 | } deriving (Eq, Show) 37 | 38 | instance Arbitrary AnyType where 39 | arbitrary = 40 | fmap AnyType genType 41 | shrink = 42 | fmap AnyType . shrinkType . getAnyType 43 | -------------------------------------------------------------------------------- /code/n/tests/Test.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Main ( 9 | main 10 | ) where 11 | 12 | -- from 'tasty' 13 | import Test.Tasty (TestTree, defaultMain, testGroup) 14 | 15 | -- local 16 | import Test.Term (termTests) 17 | import Test.Type (typeTests) 18 | 19 | main :: IO () 20 | main = defaultMain tests 21 | 22 | tests :: TestTree 23 | tests = testGroup "tests" 24 | [ typeTests 25 | , termTests 26 | ] 27 | 28 | -------------------------------------------------------------------------------- /code/n/tests/Test/Term.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Test.Term ( 9 | termTests 10 | ) where 11 | 12 | -- from 'tasty' 13 | import Test.Tasty (TestTree, testGroup) 14 | 15 | -- local 16 | import Test.Term.Eval (evalTests) 17 | import Test.Term.Infer (inferTests) 18 | import Test.Term.Structure (structureTests) 19 | import Test.Term.Text (textTests) 20 | 21 | termTests :: TestTree 22 | termTests = 23 | testGroup "term" 24 | [ structureTests 25 | , evalTests 26 | , inferTests 27 | , textTests 28 | ] 29 | -------------------------------------------------------------------------------- /code/n/tests/Test/Term/Eval.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Test.Term.Eval ( 9 | evalTests 10 | ) where 11 | 12 | -- from 'tasty' 13 | import Test.Tasty (TestTree, testGroup) 14 | 15 | -- local 16 | import Test.Term.Eval.Strict (strictTests) 17 | import Test.Term.Eval.Lazy (lazyTests) 18 | 19 | evalTests :: TestTree 20 | evalTests = testGroup "eval" 21 | [ 22 | strictTests 23 | , lazyTests 24 | ] 25 | -------------------------------------------------------------------------------- /code/n/tests/Test/Type.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Test.Type ( 9 | typeTests 10 | ) where 11 | 12 | -- from 'tasty' 13 | import Test.Tasty (TestTree, testGroup) 14 | 15 | -- local 16 | import Test.Type.Text (textTests) 17 | 18 | typeTests :: TestTree 19 | typeTests = 20 | testGroup "type" 21 | [textTests] 22 | -------------------------------------------------------------------------------- /code/n/tests/doctests.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | -- from 'doctest' 9 | import Test.DocTest 10 | 11 | main :: IO () 12 | main = doctest [ "-isrc", "src"] 13 | {- 14 | [ "Common.Parse" 15 | , "Common.Pretty" 16 | , "Term" 17 | , "Term.Eval.Value" 18 | , "Term.Eval.SmallStep" 19 | , "Term.Eval.BigStep" 20 | , "Term.Infer" 21 | , "Term.Parse" 22 | , "Term.Pretty" 23 | , "Type" 24 | , "Type.Parse" 25 | , "Type.Pretty" 26 | , "Type.Error" 27 | , "Type.Error.Pretty" 28 | ] 29 | -} 30 | 31 | -------------------------------------------------------------------------------- /code/nb/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /code/nb/default.nix: -------------------------------------------------------------------------------- 1 | { mkDerivation, ansi-wl-pprint, base, doctest, haskeline, mtl 2 | , parsers, QuickCheck, stdenv, tasty, tasty-quickcheck 3 | , transformers, trifecta, unordered-containers 4 | }: 5 | mkDerivation { 6 | pname = "nb"; 7 | version = "0.1.0.0"; 8 | src = ./.; 9 | isLibrary = true; 10 | isExecutable = true; 11 | libraryHaskellDepends = [ 12 | ansi-wl-pprint base mtl parsers QuickCheck trifecta 13 | unordered-containers 14 | ]; 15 | executableHaskellDepends = [ 16 | ansi-wl-pprint base haskeline transformers 17 | ]; 18 | testHaskellDepends = [ 19 | base doctest QuickCheck tasty tasty-quickcheck 20 | ]; 21 | license = stdenv.lib.licenses.bsd3; 22 | } 23 | -------------------------------------------------------------------------------- /code/nb/shell.nix: -------------------------------------------------------------------------------- 1 | with (import {}).pkgs; 2 | let modifiedHaskellPackages = haskellPackages.override { 3 | overrides = self: super: { 4 | n-lang = self.callPackage ./. {}; 5 | }; 6 | }; 7 | in modifiedHaskellPackages.n-lang.env 8 | 9 | -------------------------------------------------------------------------------- /code/nb/src/Common/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dalaing/little-languages/9f089f646a5344b8f7178700455a36a755d29b1f/code/nb/src/Common/.DS_Store -------------------------------------------------------------------------------- /code/nb/src/Common/Parse.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | 8 | Helpers for parsing. 9 | -} 10 | module Common.Parse ( 11 | parseFromString 12 | ) where 13 | 14 | -- from 'ansi-wl-pprint' 15 | import Text.PrettyPrint.ANSI.Leijen (Doc) 16 | 17 | -- from 'trifecta' 18 | import Text.Trifecta.Delta (Delta (..)) 19 | import Text.Trifecta.Parser (Parser, parseString) 20 | import Text.Trifecta.Result (Result (..)) 21 | 22 | -- | Runs a 'Parser' over a string and converts the result to an 'Either'. 23 | parseFromString :: Parser a 24 | -> String 25 | -> Either Doc a 26 | parseFromString p s = 27 | case parseString p (Columns 0 0) s of 28 | Success r -> Right r 29 | Failure d -> Left d 30 | -------------------------------------------------------------------------------- /code/nb/src/Term/Eval/BigStep.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : POSIX 7 | 8 | Big step rules and helpers for the NB language. 9 | 10 | This module reexports 'Term.Eval.BigStep.Strict'. 11 | There is also 'Term.Eval.BigStep.Lazy' if you need it. 12 | -} 13 | module Term.Eval.BigStep ( 14 | module Term.Eval.BigStep.Strict 15 | ) where 16 | 17 | -- local 18 | import Term.Eval.BigStep.Strict 19 | -------------------------------------------------------------------------------- /code/nb/src/Term/Eval/SmallStep.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | 8 | Small-step rules and helpers for the NB language. 9 | 10 | This module reexports 'Term.Eval.SmallStep.Strict'. 11 | There is also 'Term.Eval.SmallStep.Lazy' if you need it. 12 | -} 13 | module Term.Eval.SmallStep ( 14 | module Term.Eval.SmallStep.Strict 15 | ) where 16 | 17 | -- local 18 | import Term.Eval.SmallStep.Strict 19 | -------------------------------------------------------------------------------- /code/nb/src/Term/Eval/Value.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | 8 | Value rules and helpers for the NB language. 9 | 10 | This module reexports 'Term.Eval.Value.Strict'. 11 | There is also 'Term.Eval.Value.Lazy' if you need it. 12 | -} 13 | module Term.Eval.Value ( 14 | module Term.Eval.Value.Strict 15 | ) where 16 | 17 | -- local 18 | import Term.Eval.Value.Strict 19 | -------------------------------------------------------------------------------- /code/nb/src/Type.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | 8 | Types for the NB language. 9 | -} 10 | module Type ( 11 | Type(..) 12 | ) where 13 | 14 | -- | The types in the NB language. 15 | data Type = 16 | TyNat -- ^ The type of natural numbers. 17 | | TyBool -- ^ The type of Booleans. 18 | deriving (Eq, Ord, Show) 19 | -------------------------------------------------------------------------------- /code/nb/tests/Test.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Main ( 9 | main 10 | ) where 11 | 12 | -- from 'tasty' 13 | import Test.Tasty (TestTree, defaultMain, testGroup) 14 | 15 | -- local 16 | import Test.Term (termTests) 17 | import Test.Type (typeTests) 18 | 19 | main :: IO () 20 | main = defaultMain tests 21 | 22 | tests :: TestTree 23 | tests = testGroup "tests" 24 | [ typeTests 25 | , termTests 26 | ] 27 | 28 | -------------------------------------------------------------------------------- /code/nb/tests/Test/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dalaing/little-languages/9f089f646a5344b8f7178700455a36a755d29b1f/code/nb/tests/Test/.DS_Store -------------------------------------------------------------------------------- /code/nb/tests/Test/Term.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Test.Term ( 9 | termTests 10 | ) where 11 | 12 | -- from 'tasty' 13 | import Test.Tasty (TestTree, testGroup) 14 | 15 | -- local 16 | import Test.Term.Eval (evalTests) 17 | import Test.Term.Infer (inferTests) 18 | import Test.Term.Structure (structureTests) 19 | import Test.Term.Text (textTests) 20 | 21 | termTests :: TestTree 22 | termTests = 23 | testGroup "term" 24 | [ structureTests 25 | , evalTests 26 | , inferTests 27 | , textTests 28 | ] 29 | 30 | -------------------------------------------------------------------------------- /code/nb/tests/Test/Term/Eval.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Test.Term.Eval ( 9 | evalTests 10 | ) where 11 | 12 | -- from 'tasty' 13 | import Test.Tasty (TestTree, testGroup) 14 | 15 | -- local 16 | import Test.Term.Eval.Strict (strictTests) 17 | import Test.Term.Eval.Lazy (lazyTests) 18 | 19 | evalTests :: TestTree 20 | evalTests = testGroup "eval" 21 | [ 22 | strictTests 23 | , lazyTests 24 | ] 25 | -------------------------------------------------------------------------------- /code/nb/tests/Test/Type.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Test.Type ( 9 | typeTests 10 | ) where 11 | 12 | -- from 'tasty' 13 | import Test.Tasty (TestTree, testGroup) 14 | 15 | -- local 16 | import Test.Type.Text (textTests) 17 | 18 | typeTests :: TestTree 19 | typeTests = 20 | testGroup "type" 21 | [textTests] 22 | -------------------------------------------------------------------------------- /code/nb/tests/doctests.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | -- from 'doctest' 9 | import Test.DocTest 10 | 11 | main :: IO () 12 | main = doctest [ "-isrc", "src"] 13 | {- 14 | [ "Common.Parse" 15 | , "Common.Pretty" 16 | , "Term" 17 | , "Term.Eval.Value" 18 | , "Term.Eval.SmallStep" 19 | , "Term.Eval.BigStep" 20 | , "Term.Infer" 21 | , "Term.Parse" 22 | , "Term.Pretty" 23 | , "Type" 24 | , "Type.Parse" 25 | , "Type.Pretty" 26 | , "Type.Error" 27 | , "Type.Error.Pretty" 28 | ] 29 | -} 30 | 31 | -------------------------------------------------------------------------------- /code/old/modular/b-lang/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /code/old/modular/b-lang/default.nix: -------------------------------------------------------------------------------- 1 | { mkDerivation, ansi-wl-pprint, base, common-lang, lens, mtl 2 | , parsers, QuickCheck, stdenv, trifecta, unordered-containers 3 | }: 4 | mkDerivation { 5 | pname = "b-lang"; 6 | version = "0.1.0.0"; 7 | src = ./.; 8 | libraryHaskellDepends = [ 9 | ansi-wl-pprint base common-lang lens mtl parsers QuickCheck 10 | trifecta unordered-containers 11 | ]; 12 | license = stdenv.lib.licenses.bsd3; 13 | } 14 | -------------------------------------------------------------------------------- /code/old/modular/b-lang/shell.nix: -------------------------------------------------------------------------------- 1 | with (import {}).pkgs; 2 | let modifiedHaskellPackages = haskellPackages.override { 3 | overrides = self: super: { 4 | common-lang = self.callPackage ../common-lang {}; 5 | b-lang = self.callPackage ./. {}; 6 | }; 7 | }; 8 | in pkgs.myEnvFun { 9 | name = modifiedHaskellPackages.b-lang.name; 10 | buildInputs = [ 11 | (modifiedHaskellPackages.ghcWithPackages (hs: ([ 12 | hs.cabal-install 13 | hs.hscolour 14 | hs.ghc-mod 15 | ] ++ hs.b-lang.propagatedNativeBuildInputs))) 16 | ]; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /code/old/modular/b-lang/src/Component/Term/Bool/Eval/Value.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Component.Term.Bool.Eval.Value ( 9 | valueInput 10 | ) where 11 | 12 | import Control.Lens (preview, review) 13 | 14 | import Component.Term.Eval.Value (ValueRule(..), ValueInput(..)) 15 | 16 | import Component.Term.Bool (AsBoolTerm(..), WithBoolTerm) 17 | 18 | valueTmFalse :: WithBoolTerm tm 19 | => tm nTy nTm a 20 | -> Maybe (tm nTy nTm a) 21 | valueTmFalse = 22 | fmap (review _TmFalse) . 23 | preview _TmFalse 24 | 25 | valueTmTrue :: WithBoolTerm tm 26 | => tm nTy nTm a 27 | -> Maybe (tm nTy nTm a) 28 | valueTmTrue = 29 | fmap (review _TmTrue) . 30 | preview _TmTrue 31 | 32 | valueInput :: WithBoolTerm tm 33 | => ValueInput tm 34 | valueInput = 35 | ValueInput 36 | [ ValueBase valueTmFalse 37 | , ValueBase valueTmTrue 38 | ] 39 | -------------------------------------------------------------------------------- /code/old/modular/b-lang/src/Component/Term/Bool/Eval/Values.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Component.Term.Bool.Eval.Value ( 9 | ) where 10 | -------------------------------------------------------------------------------- /code/old/modular/b-lang/src/Component/Type/Bool/Pretty.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | {-# LANGUAGE FlexibleContexts #-} 9 | module Component.Type.Bool.Pretty ( 10 | prettyTypeInput 11 | ) where 12 | 13 | import Control.Lens (preview) 14 | import Text.PrettyPrint.ANSI.Leijen (Doc) 15 | 16 | import Common.Pretty 17 | import Component.Type.Pretty (PrettyTypeInput(..), PrettyTypeRule(..)) 18 | 19 | import Component.Type.Bool (AsBoolType(..), WithBoolType) 20 | 21 | prettyTyBool :: WithBoolType ty 22 | => ty n 23 | -> Maybe Doc 24 | prettyTyBool = 25 | fmap (const . reservedConstructor $ "Bool") . 26 | preview _TyBool 27 | 28 | prettyTypeInput :: WithBoolType ty 29 | => PrettyTypeInput ty 30 | prettyTypeInput = 31 | PrettyTypeInput 32 | [PrettyTypeBase prettyTyBool] 33 | -------------------------------------------------------------------------------- /code/old/modular/cabal.project: -------------------------------------------------------------------------------- 1 | packages: common-lang/ 2 | b-lang/ 3 | n-lang/ 4 | i-lang/ 5 | nb-lang/ 6 | stlc-lang/ 7 | test-lang/ 8 | -------------------------------------------------------------------------------- /code/old/modular/common-lang/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /code/old/modular/common-lang/default.nix: -------------------------------------------------------------------------------- 1 | { mkDerivation, ansi-wl-pprint, base, lens, mtl, parsers 2 | , QuickCheck, stdenv, trifecta, unordered-containers 3 | }: 4 | mkDerivation { 5 | pname = "common-lang"; 6 | version = "0.1.0.0"; 7 | src = ./.; 8 | libraryHaskellDepends = [ 9 | ansi-wl-pprint base lens mtl parsers QuickCheck trifecta 10 | unordered-containers 11 | ]; 12 | license = stdenv.lib.licenses.bsd3; 13 | } 14 | -------------------------------------------------------------------------------- /code/old/modular/common-lang/result: -------------------------------------------------------------------------------- 1 | /nix/store/bfk5vz29wzjq77yglcgwx9m3g6nxrcpj-common-lang-0.1.0.0 -------------------------------------------------------------------------------- /code/old/modular/common-lang/shell.nix: -------------------------------------------------------------------------------- 1 | with (import {}).pkgs; 2 | let modifiedHaskellPackages = haskellPackages.override { 3 | overrides = self: super: { 4 | common-lang = self.callPackage ./. {}; 5 | }; 6 | }; 7 | in modifiedHaskellPackages.common-lang.env 8 | 9 | -------------------------------------------------------------------------------- /code/old/modular/common-lang/src/Bifunctor2.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Bifunctor2 ( 9 | Bifunctor2(..) 10 | ) where 11 | 12 | import Data.Bifunctor (Bifunctor(..)) 13 | import Data.Proxy (Proxy) 14 | import Data.Constraint (Dict) 15 | 16 | class Bifunctor2 tm where 17 | bifunctor2 :: Proxy nTy -> Dict (Bifunctor (tm nTy)) 18 | -------------------------------------------------------------------------------- /code/old/modular/common-lang/src/Bound2.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Bound2 ( 9 | Bound2(..) 10 | , Bound3(..) 11 | ) where 12 | 13 | class Bound2 t where 14 | (>>>>=) :: Monad (f n) => t f n a -> (a -> f n b) -> t f n b 15 | 16 | class Bound3 t where 17 | (>>>>>=) :: Monad (f m n) => t f m n a -> (a -> f m n b) -> t f m n b 18 | -------------------------------------------------------------------------------- /code/old/modular/common-lang/src/Common/Note.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | {-# LANGUAGE MultiParamTypeClasses #-} 9 | {-# LANGUAGE FlexibleInstances #-} 10 | module Common.Note ( 11 | TranslateNote(..) 12 | ) where 13 | 14 | -- TODO should this be a lens? 15 | class TranslateNote nTm nTy where 16 | translateNote :: nTm -> nTy 17 | 18 | instance TranslateNote a a where 19 | translateNote = id 20 | -------------------------------------------------------------------------------- /code/old/modular/common-lang/src/Common/Text.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Common.Text ( 9 | ExpressionInfo(..) 10 | , Assoc(..) 11 | , combineTables 12 | ) where 13 | 14 | import Text.Parser.Expression (Assoc(..), OperatorTable) 15 | 16 | data ExpressionInfo = 17 | ExpressionInfo { 18 | _assoc :: Assoc 19 | , _precedence :: Int 20 | } deriving (Eq, Ord, Show) 21 | 22 | combineTables :: [OperatorTable m a] 23 | -> OperatorTable m a 24 | combineTables os = 25 | foldr (zipWith (++) . pad) (pad []) os 26 | where 27 | l = maximum . map length $ os 28 | pad ls = replicate (l - length ls) [] ++ ls 29 | -------------------------------------------------------------------------------- /code/old/modular/common-lang/src/Component/Term/Note/Eval/BigStep.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Component.Term.Note.Eval.BigStep ( 9 | bigStepInput 10 | ) where 11 | 12 | import Control.Lens (preview, review) 13 | 14 | import Component.Term.Eval.BigStep (BigStepRule(..), BigStepInput(..)) 15 | import Component.Term.Note (AsNoteTerm(..), WithNoteTerm) 16 | 17 | bigStepTmNote :: WithNoteTerm tm 18 | => (tm nTy nTm a -> Maybe (tm nTy nTm a)) 19 | -> tm nTy nTm a 20 | -> Maybe (tm nTy nTm a) 21 | bigStepTmNote bigStep tm = do 22 | (n, tm1) <- preview _TmNote tm 23 | tm1' <- bigStep tm1 24 | return $ review _TmNote (n, tm1') 25 | 26 | bigStepInput :: WithNoteTerm tm 27 | => BigStepInput tm 28 | bigStepInput = 29 | BigStepInput 30 | [BigStepRecurse bigStepTmNote] 31 | -------------------------------------------------------------------------------- /code/old/modular/common-lang/src/Component/Term/Note/Eval/SmallStep.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Component.Term.Note.Eval.SmallStep ( 9 | smallStepInput 10 | ) where 11 | 12 | import Control.Lens (preview, review) 13 | 14 | import Component.Term.Eval.SmallStep (SmallStepRule(..), SmallStepInput(..)) 15 | import Component.Term.Note (AsNoteTerm(..), WithNoteTerm) 16 | 17 | smallStepTmNote :: WithNoteTerm tm 18 | => (tm nTy nTm a -> Maybe (tm nTy nTm a)) 19 | -> tm nTy nTm a 20 | -> Maybe (tm nTy nTm a) 21 | smallStepTmNote smallStep tm = do 22 | (_, tm1) <- preview _TmNote tm 23 | smallStep tm1 24 | 25 | smallStepInput :: WithNoteTerm tm 26 | => SmallStepInput tm 27 | smallStepInput = 28 | SmallStepInput 29 | [SmallStepRecurse smallStepTmNote] 30 | -------------------------------------------------------------------------------- /code/old/modular/common-lang/src/Component/Term/Note/Eval/Value.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Component.Term.Note.Eval.Value ( 9 | valueInput 10 | ) where 11 | 12 | import Control.Lens (preview, review) 13 | 14 | import Component.Term.Eval.Value (ValueRule(..), ValueInput(..)) 15 | import Component.Term.Note (AsNoteTerm(..), WithNoteTerm) 16 | 17 | valueTmNote :: WithNoteTerm tm 18 | => (tm nTy nTm a -> Maybe (tm nTy nTm a)) 19 | -> tm nTy nTm a 20 | -> Maybe (tm nTy nTm a) 21 | valueTmNote value tm = do 22 | (_, tm1) <- preview _TmNote tm 23 | value tm1 24 | 25 | valueInput :: WithNoteTerm tm 26 | => ValueInput tm 27 | valueInput = 28 | ValueInput 29 | [ValueRecurse valueTmNote] 30 | -------------------------------------------------------------------------------- /code/old/modular/common-lang/src/Component/Term/Note/Gen.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Component.Term.Note.Gen ( 9 | genTermInput 10 | ) where 11 | 12 | import Component.Term.Gen (GenTermInput(..)) 13 | 14 | genTermInput :: GenTermInput ty tm 15 | genTermInput = mempty 16 | -------------------------------------------------------------------------------- /code/old/modular/common-lang/src/Component/Term/Note/Parse.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Component.Term.Note.Parse ( 9 | parseTermInput 10 | ) where 11 | 12 | import Component.Term.Parse (ParseTermInput(..)) 13 | 14 | parseTermInput :: ParseTermInput ty tm 15 | parseTermInput = mempty 16 | -------------------------------------------------------------------------------- /code/old/modular/common-lang/src/Component/Term/Note/Pretty.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | {-# LANGUAGE MultiParamTypeClasses #-} 9 | module Component.Term.Note.Pretty ( 10 | prettyTermInput 11 | ) where 12 | 13 | import Control.Lens (preview) 14 | import Text.PrettyPrint.ANSI.Leijen (Doc) 15 | 16 | import Component.Term.Note (AsNoteTerm (..), WithNoteTerm) 17 | import Component.Term.Pretty (PrettyTermInput (..), 18 | PrettyTermRule (..)) 19 | 20 | prettyTmNote :: WithNoteTerm tm 21 | => (tm nTy nTm a -> Doc) 22 | -> tm nTy nTm a 23 | -> Maybe Doc 24 | prettyTmNote prettyTerm = 25 | fmap (prettyTerm . snd) . 26 | preview _TmNote 27 | 28 | prettyTermInput :: WithNoteTerm tm 29 | => PrettyTermInput ty tm 30 | prettyTermInput = 31 | PrettyTermInput 32 | [PrettyTermRecurse prettyTmNote] 33 | -------------------------------------------------------------------------------- /code/old/modular/common-lang/src/Component/Term/Note/Strip.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | {-# LANGUAGE FlexibleInstances #-} 9 | {-# LANGUAGE FunctionalDependencies #-} 10 | {-# LANGUAGE MultiParamTypeClasses #-} 11 | module Component.Term.Note.Strip ( 12 | StripNoteTerm(..) 13 | ) where 14 | 15 | class StripNoteTerm x p | x -> p where 16 | mapMaybeNoteTerm :: (nTm -> Maybe mTm) -> x nTy nTm a -> p nTy mTm a 17 | 18 | stripNoteTerm :: x nTy nTm a -> p nTy mTm a 19 | stripNoteTerm = mapMaybeNoteTerm (const Nothing) 20 | 21 | -------------------------------------------------------------------------------- /code/old/modular/common-lang/src/Component/Term/Note/SubTerm.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | {-# LANGUAGE RankNTypes #-} 9 | {-# LANGUAGE ScopedTypeVariables #-} 10 | module Component.Term.Note.SubTerm ( 11 | subTermInput 12 | ) where 13 | 14 | import Control.Lens (preview) 15 | 16 | import Component.Term.SubTerm (SubTermInput(..), SubTermRule(..)) 17 | 18 | import Component.Term.Note (AsNoteTerm(..), WithNoteTerm) 19 | 20 | subTermTmNote :: WithNoteTerm tm 21 | => (tm nTy nTm a -> [tm nTy nTm a]) 22 | -> tm nTy nTm a 23 | -> Maybe [tm nTy nTm a] 24 | subTermTmNote subTerms tm = 25 | fmap ((tm :) . subTerms . snd) . 26 | preview _TmNote $ 27 | tm 28 | 29 | subTermInput :: WithNoteTerm tm 30 | => SubTermInput tm 31 | subTermInput = 32 | SubTermInput 33 | [SubTermRecurse subTermTmNote] 34 | -------------------------------------------------------------------------------- /code/old/modular/common-lang/src/Component/Type/Error/ExpectedEq/Class.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | {-# LANGUAGE FunctionalDependencies #-} 9 | {-# LANGUAGE MultiParamTypeClasses #-} 10 | module Component.Type.Error.ExpectedEq.Class ( 11 | AsExpectedEq(..) 12 | ) where 13 | 14 | import Control.Lens.Prism (Prism') 15 | 16 | class AsExpectedEq e ty | e -> ty where 17 | _ExpectedEq :: Prism' (e n a) (ty n, ty n) 18 | -------------------------------------------------------------------------------- /code/old/modular/common-lang/src/Component/Type/Error/Unexpected/Class.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | {-# LANGUAGE FunctionalDependencies #-} 9 | {-# LANGUAGE MultiParamTypeClasses #-} 10 | module Component.Type.Error.Unexpected.Class ( 11 | AsUnexpected(..) 12 | ) where 13 | 14 | import Control.Lens.Prism (Prism') 15 | 16 | class AsUnexpected e ty | e -> ty where 17 | _Unexpected :: Prism' (e n a) (ty n, ty n) 18 | -------------------------------------------------------------------------------- /code/old/modular/common-lang/src/Component/Type/Error/UnknownType/Class.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Component.Type.Error.UnknownType.Class ( 9 | AsUnknownType(..) 10 | ) where 11 | 12 | import Control.Lens.Prism (Prism') 13 | 14 | class AsUnknownType e where 15 | _UnknownType :: Prism' (e n a) () 16 | -------------------------------------------------------------------------------- /code/old/modular/common-lang/src/Component/Type/Note/Gen.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Component.Type.Note.Gen ( 9 | genTypeInput 10 | ) where 11 | 12 | import Component.Type.Gen (GenTypeInput(..)) 13 | 14 | genTypeInput :: GenTypeInput ty 15 | genTypeInput = mempty 16 | -------------------------------------------------------------------------------- /code/old/modular/common-lang/src/Component/Type/Note/Parse.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Component.Type.Note.Parse ( 9 | parseTypeInput 10 | ) where 11 | 12 | import Component.Type.Parse (ParseTypeInput(..)) 13 | 14 | parseTypeInput :: ParseTypeInput ty 15 | parseTypeInput = mempty 16 | -------------------------------------------------------------------------------- /code/old/modular/common-lang/src/Component/Type/Note/Pretty.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | {-# LANGUAGE MultiParamTypeClasses #-} 9 | module Component.Type.Note.Pretty ( 10 | prettyTypeInput 11 | ) where 12 | 13 | import Control.Lens (preview) 14 | import Text.PrettyPrint.ANSI.Leijen (Doc) 15 | 16 | import Component.Type.Note (AsNoteType (..), WithNoteType) 17 | import Component.Type.Pretty (PrettyTypeInput (..), 18 | PrettyTypeRule (..)) 19 | 20 | prettyTyNote :: WithNoteType ty 21 | => (ty n -> Doc) 22 | -> ty n 23 | -> Maybe Doc 24 | prettyTyNote prettyType = 25 | fmap (prettyType . snd) . 26 | preview _TyNote 27 | 28 | prettyTypeInput :: WithNoteType ty 29 | => PrettyTypeInput ty 30 | prettyTypeInput = 31 | PrettyTypeInput 32 | [PrettyTypeRecurse prettyTyNote] 33 | -------------------------------------------------------------------------------- /code/old/modular/common-lang/src/Extras.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | {-# LANGUAGE TypeOperators #-} 9 | module Extras ( 10 | Eq1(..) 11 | , Show1(..) 12 | , Eq2(..) 13 | , Show2(..) 14 | , Eq3(..) 15 | , Show3(..) 16 | , Monoid2(..) 17 | ) where 18 | 19 | import Data.Constraint 20 | 21 | class Eq1 ty where 22 | spanEq1 :: Eq nTy :- Eq (ty nTy) 23 | 24 | class Show1 ty where 25 | spanShow1 :: Show nTy :- Show (ty nTy) 26 | 27 | class Eq2 e where 28 | spanEq2 :: (Eq n, Eq a) :- Eq (e n a) 29 | 30 | class Show2 e where 31 | spanShow2 :: (Show n, Show a) :- Show (e n a) 32 | 33 | class Eq3 tm where 34 | spanEq3 :: (Eq nTy, Eq nTm, Eq a) :- Eq (tm nTy nTm a) 35 | 36 | class Show3 tm where 37 | spanShow3 :: (Show nTy, Show nTm, Show a) :- Show (tm nTy nTm a) 38 | 39 | class Monoid2 ctx where 40 | spanMonoid2 :: Ord a :- Monoid (ctx n a) 41 | -------------------------------------------------------------------------------- /code/old/modular/common-lang/src/Tests/Type.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Tests.Type ( 9 | mkTypeTests 10 | ) where 11 | 12 | import Data.Proxy (Proxy) 13 | 14 | import Test.Tasty (TestTree, testGroup) 15 | import Text.Trifecta.Rendering (Span) 16 | 17 | import Component (ComponentOutput) 18 | import Tests.Type.Text (mkTextTests) 19 | import Extras (Eq1, Show1) 20 | 21 | mkTypeTests :: ( Eq1 ty 22 | , Show1 ty 23 | ) 24 | => ComponentOutput r e ty tm 25 | -> Proxy nTy 26 | -> TestTree 27 | mkTypeTests c _ = 28 | testGroup "type" 29 | [mkTextTests c] 30 | -------------------------------------------------------------------------------- /code/old/modular/i-lang/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /code/old/modular/i-lang/src/Component/Term/Int/Eval/Value.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Component.Term.Int.Eval.Value ( 9 | valueInput 10 | ) where 11 | 12 | import Control.Lens (preview, review) 13 | 14 | import Component.Term.Eval.Value (ValueRule(..), ValueInput(..)) 15 | 16 | import Component.Term.Int (AsIntTerm(..), WithIntTerm) 17 | 18 | valueTmInt :: WithIntTerm tm 19 | => tm nTy nTm a 20 | -> Maybe (tm nTy nTm a) 21 | valueTmInt = 22 | fmap (review _TmIntLit) . 23 | preview _TmIntLit 24 | 25 | valueInput :: WithIntTerm tm 26 | => ValueInput tm 27 | valueInput = 28 | ValueInput 29 | [ValueBase valueTmInt] 30 | -------------------------------------------------------------------------------- /code/old/modular/i-lang/src/Component/Term/Int/Eval/Values.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Component.Term.Bool.Eval.Value ( 9 | ) where 10 | -------------------------------------------------------------------------------- /code/old/modular/i-lang/src/Component/Type/Int/Parse.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Component.Type.Int.Parse ( 9 | parseTypeInput 10 | ) where 11 | 12 | import Control.Lens (view, review) 13 | import Text.Parser.Combinators (()) 14 | import Text.Trifecta.Parser (Parser) 15 | 16 | import Common.Parse (reserveConstructors, ParserHelperOutput, HasParserHelperOutput(..)) 17 | import Component.Type.Parse (ParseTypeInput(..), ParseTypeRule(..)) 18 | 19 | import Component.Type.Int (AsIntType(..), WithIntType) 20 | 21 | -- | 22 | parseTyInt :: WithIntType ty 23 | => ParserHelperOutput 24 | -> Parser (ty n) -- ^ 25 | parseTyInt h = 26 | let 27 | rc = view reservedConstructor h 28 | in 29 | review _TyInt () <$ rc "Int" "Int" 30 | 31 | parseTypeInput :: WithIntType ty 32 | => ParseTypeInput ty 33 | parseTypeInput = 34 | ParseTypeInput 35 | [ParseTypeBase (reserveConstructors ["Int"]) parseTyInt] 36 | -------------------------------------------------------------------------------- /code/old/modular/i-lang/src/Component/Type/Int/Pretty.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Component.Type.Int.Pretty ( 9 | prettyTypeInput 10 | ) where 11 | 12 | import Control.Lens (preview) 13 | import Text.PrettyPrint.ANSI.Leijen (Doc) 14 | 15 | import Common.Pretty 16 | import Component.Type.Pretty (PrettyTypeInput(..), PrettyTypeRule(..)) 17 | 18 | import Component.Type.Int (AsIntType(..), WithIntType) 19 | 20 | prettyTyInt :: WithIntType ty 21 | => ty n 22 | -> Maybe Doc 23 | prettyTyInt = 24 | fmap (const . reservedConstructor $ "Int") . 25 | preview _TyInt 26 | 27 | prettyTypeInput :: WithIntType ty 28 | => PrettyTypeInput ty 29 | prettyTypeInput = 30 | PrettyTypeInput 31 | [PrettyTypeBase prettyTyInt] 32 | -------------------------------------------------------------------------------- /code/old/modular/n-lang/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /code/old/modular/n-lang/src/Component/Term/Nat/Eval/Values.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Component.Term.Bool.Eval.Value ( 9 | ) where 10 | -------------------------------------------------------------------------------- /code/old/modular/n-lang/src/Component/Type/Nat/Parse.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Component.Type.Nat.Parse ( 9 | parseTypeInput 10 | ) where 11 | 12 | import Control.Lens (view, review) 13 | import Text.Parser.Combinators (()) 14 | import Text.Trifecta.Parser (Parser) 15 | 16 | import Common.Parse (reserveConstructors, ParserHelperOutput, HasParserHelperOutput(..)) 17 | import Component.Type.Parse (ParseTypeInput(..), ParseTypeRule(..)) 18 | 19 | import Component.Type.Nat (AsNatType(..), WithNatType) 20 | 21 | -- | 22 | parseTyNat :: WithNatType ty 23 | => ParserHelperOutput 24 | -> Parser (ty n) -- ^ 25 | parseTyNat h = 26 | let 27 | rc = view reservedConstructor h 28 | in 29 | review _TyNat () <$ rc "Nat" "Nat" 30 | 31 | parseTypeInput :: WithNatType ty 32 | => ParseTypeInput ty 33 | parseTypeInput = 34 | ParseTypeInput 35 | [ParseTypeBase (reserveConstructors ["Nat"]) parseTyNat] 36 | -------------------------------------------------------------------------------- /code/old/modular/n-lang/src/Component/Type/Nat/Pretty.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Component.Type.Nat.Pretty ( 9 | prettyTypeInput 10 | ) where 11 | 12 | import Control.Lens (preview) 13 | import Text.PrettyPrint.ANSI.Leijen (Doc) 14 | 15 | import Common.Pretty 16 | import Component.Type.Pretty (PrettyTypeInput(..), PrettyTypeRule(..)) 17 | 18 | import Component.Type.Nat (AsNatType(..), WithNatType) 19 | 20 | prettyTyNat :: WithNatType ty 21 | => ty n 22 | -> Maybe Doc 23 | prettyTyNat = 24 | fmap (const . reservedConstructor $ "Nat") . 25 | preview _TyNat 26 | 27 | prettyTypeInput :: WithNatType ty 28 | => PrettyTypeInput ty 29 | prettyTypeInput = 30 | PrettyTypeInput 31 | [PrettyTypeBase prettyTyNat] 32 | -------------------------------------------------------------------------------- /code/old/modular/nb-lang/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /code/old/modular/nb-lang/src/Component/Term/NatBool/Eval/Value.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Component.Term.NatBool.Eval.Value ( 9 | valueInput 10 | ) where 11 | 12 | import Component.Term.Eval.Value (ValueInput(..)) 13 | 14 | import Component.Term.NatBool (WithNatBoolTerm) 15 | 16 | valueInput :: WithNatBoolTerm tm 17 | => ValueInput tm 18 | valueInput = mempty 19 | -------------------------------------------------------------------------------- /code/old/modular/nb-lang/src/Component/Term/NatBool/Eval/Values.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Component.Term.Bool.Eval.Value ( 9 | ) where 10 | -------------------------------------------------------------------------------- /code/old/modular/nb-lang/src/Component/Term/NatBool/SubTerm.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Component.Term.NatBool.SubTerm ( 9 | subTermInput 10 | ) where 11 | 12 | import Control.Lens (preview) 13 | 14 | import Component.Term.SubTerm (SubTermInput(..), SubTermRule(..)) 15 | 16 | import Component.Term.NatBool (AsNatBoolTerm(..), WithNatBoolTerm) 17 | 18 | subTermTmIsZero :: WithNatBoolTerm tm 19 | => (tm nTy nTm a -> [tm nTy nTm a]) 20 | -> tm nTy nTm a 21 | -> Maybe [tm nTy nTm a] 22 | subTermTmIsZero subTerms tm = 23 | fmap ((tm :) . subTerms) . 24 | preview _TmIsZero $ 25 | tm 26 | 27 | subTermInput :: WithNatBoolTerm tm 28 | => SubTermInput tm 29 | subTermInput = 30 | SubTermInput 31 | [SubTermRecurse subTermTmIsZero] 32 | -------------------------------------------------------------------------------- /code/old/modular/stlc-lang/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /code/old/modular/stlc-lang/projectile: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dalaing/little-languages/9f089f646a5344b8f7178700455a36a755d29b1f/code/old/modular/stlc-lang/projectile -------------------------------------------------------------------------------- /code/old/modular/stlc-lang/src/Component/Term/STLC/Eval/Value.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Component.Term.STLC.Eval.Value ( 9 | valueInput 10 | ) where 11 | 12 | import Control.Lens (preview, review) 13 | 14 | import Component.Term.Eval.Value (ValueRule(..), ValueInput(..)) 15 | 16 | import Component.Term.STLC (AsSTLCTerm(..), WithSTLCTerm) 17 | 18 | valueTmLam :: WithSTLCTerm tm ty 19 | => tm nTy nTm a 20 | -> Maybe (tm nTy nTm a) 21 | valueTmLam = 22 | fmap (review _TmLam) . 23 | preview _TmLam 24 | 25 | valueInput :: WithSTLCTerm tm ty 26 | => ValueInput tm 27 | valueInput = 28 | ValueInput 29 | [ValueBase valueTmLam] 30 | -------------------------------------------------------------------------------- /code/old/modular/test-i-lang/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /code/old/modular/test-i-lang/repl/Main.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Main ( 9 | main 10 | ) where 11 | 12 | import Data.Monoid ((<>)) 13 | import Text.Trifecta.Rendering (Span(..)) 14 | 15 | import Repl (mkRepl) 16 | import Language (mkLanguageDefaultParser) 17 | import Component (ComponentInput) 18 | 19 | import TestLanguage (languageRules, errorRules, TypeError, Type, Term(..)) 20 | 21 | main :: IO () 22 | main = 23 | mkRepl . 24 | mkLanguageDefaultParser $ 25 | -- (languageRules <> errorRules) 26 | ((languageRules <> errorRules) :: ComponentInput () TypeError Type Term) 27 | -------------------------------------------------------------------------------- /code/old/modular/test-i-lang/tests/Test.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Main ( 9 | main 10 | ) where 11 | 12 | import Data.Monoid ((<>)) 13 | import Data.Proxy (Proxy(..)) 14 | 15 | import Test.Tasty (defaultMain) 16 | import Text.Trifecta.Rendering (Span) 17 | 18 | import Tests (mkTests) 19 | import Component (ComponentInput) 20 | import Language (mkLanguageDefaultParser) 21 | 22 | import TestLanguage (languageRules, errorRules, TypeError, Type, Term) 23 | 24 | main :: IO () 25 | main = 26 | defaultMain . 27 | mkTests (Proxy :: Proxy Span) (Proxy :: Proxy Span) . 28 | mkLanguageDefaultParser $ 29 | ((languageRules <> errorRules) :: ComponentInput () TypeError Type Term) 30 | 31 | -------------------------------------------------------------------------------- /code/old/modular/test-lang/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /code/old/modular/test-lang/repl/Main.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Main ( 9 | main 10 | ) where 11 | 12 | import Data.Monoid ((<>)) 13 | 14 | import Repl (mkRepl) 15 | import Language (mkLanguageDefaultParser) 16 | import Component (ComponentInput) 17 | import Component.Type.STLC (Context) 18 | 19 | import TestLanguage (languageRules, errorRulesSrcLoc, TypeError, Type, Term) 20 | 21 | main :: IO () 22 | main = 23 | mkRepl . 24 | mkLanguageDefaultParser $ 25 | ((languageRules <> errorRulesSrcLoc) :: ComponentInput (Context Type) TypeError Type Term ) 26 | -------------------------------------------------------------------------------- /code/old/modular/test-lang/tests/Test.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Copyright : (c) Dave Laing, 2016 3 | License : BSD3 4 | Maintainer : dave.laing.80@gmail.com 5 | Stability : experimental 6 | Portability : non-portable 7 | -} 8 | module Main ( 9 | main 10 | ) where 11 | 12 | import Data.Proxy (Proxy(..)) 13 | 14 | import Test.Tasty (defaultMain) 15 | import Data.Monoid ((<>)) 16 | import Text.Trifecta.Rendering (Span) 17 | 18 | import Tests (mkTests) 19 | import Component (ComponentInput) 20 | import Language (mkLanguageDefaultParser) 21 | import Component.Type.STLC (Context) 22 | 23 | import TestLanguage (languageRules, errorRules, TypeError, Type, Term) 24 | 25 | main :: IO () 26 | main = 27 | defaultMain . 28 | mkTests (Proxy :: Proxy Span) (Proxy :: Proxy Span). 29 | mkLanguageDefaultParser $ 30 | ((languageRules <> errorRules) :: ComponentInput (Context Type) TypeError Type Term) 31 | 32 | -------------------------------------------------------------------------------- /code/old/multityped/ll-util/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /code/old/multityped/ll-util/default.nix: -------------------------------------------------------------------------------- 1 | { mkDerivation, ansi-wl-pprint, base, bifunctors, mtl, stdenv 2 | , trifecta 3 | }: 4 | mkDerivation { 5 | pname = "ll-util"; 6 | version = "0.1.0.0"; 7 | src = ./.; 8 | libraryHaskellDepends = [ 9 | ansi-wl-pprint base bifunctors mtl trifecta 10 | ]; 11 | license = stdenv.lib.licenses.bsd3; 12 | } 13 | -------------------------------------------------------------------------------- /code/old/multityped/ll-util/ll-util.cabal: -------------------------------------------------------------------------------- 1 | -- Initial ll-util.cabal generated by cabal init. For further 2 | -- documentation, see http://haskell.org/cabal/users-guide/ 3 | 4 | name: ll-util 5 | version: 0.1.0.0 6 | -- synopsis: 7 | -- description: 8 | license: BSD3 9 | license-file: LICENSE 10 | author: Dave Laing 11 | maintainer: dave.laing.80@gmail.com 12 | -- copyright: 13 | -- category: 14 | build-type: Simple 15 | -- extra-source-files: 16 | cabal-version: >=1.10 17 | 18 | library 19 | exposed-modules: Cofree1, ExpressionPrinter, Fix1 20 | -- other-modules: 21 | -- other-extensions: 22 | build-depends: base >=4.8 && <4.9 23 | , bifunctors >= 5.2 && < 5.3 24 | , ansi-wl-pprint >=0.6 && <0.7 25 | , mtl >= 2.2 && < 2.3 26 | , trifecta >= 1.5 && < 1.6 27 | hs-source-dirs: src 28 | default-language: Haskell2010 29 | -------------------------------------------------------------------------------- /code/old/multityped/ll-util/shell.nix: -------------------------------------------------------------------------------- 1 | { nixpkgs ? import {}, compiler ? "default" }: 2 | 3 | let 4 | 5 | inherit (nixpkgs) pkgs; 6 | 7 | f = { mkDerivation, ansi-wl-pprint, base, bifunctors, mtl, stdenv 8 | , trifecta 9 | }: 10 | mkDerivation { 11 | pname = "ll-util"; 12 | version = "0.1.0.0"; 13 | src = ./.; 14 | libraryHaskellDepends = [ 15 | ansi-wl-pprint base bifunctors mtl trifecta 16 | ]; 17 | license = stdenv.lib.licenses.bsd3; 18 | }; 19 | 20 | haskellPackages = if compiler == "default" 21 | then pkgs.haskellPackages 22 | else pkgs.haskell.packages.${compiler}; 23 | 24 | drv = haskellPackages.callPackage f {}; 25 | 26 | in 27 | 28 | if pkgs.lib.inNixShell then drv.env else drv 29 | -------------------------------------------------------------------------------- /code/old/multityped/ll-util/src/Fix1.hs: -------------------------------------------------------------------------------- 1 | module Fix1 where 2 | 3 | import Data.Bifunctor 4 | import Data.Bifoldable 5 | import Data.Bitraversable 6 | 7 | data Fix1 f a = Fix1 { unFix1 :: f (Fix1 f a) a } 8 | 9 | instance Bifunctor f => Functor (Fix1 f) where 10 | fmap f = Fix1 . bimap (fmap f) f . unFix1 11 | 12 | instance Bifoldable f => Foldable (Fix1 f) where 13 | foldMap f = bifoldMap (foldMap f) f . unFix1 14 | 15 | instance Bitraversable f => Traversable (Fix1 f) where 16 | traverse f = fmap Fix1 . bitraverse (traverse f) f . unFix1 17 | -------------------------------------------------------------------------------- /code/old/multityped/ll-util/src/Parse.hs: -------------------------------------------------------------------------------- 1 | module Parse where 2 | 3 | import Control.Monad.Except 4 | 5 | import qualified Text.Trifecta as T 6 | import Text.PrettyPrint.ANSI.Leijen (Doc) 7 | 8 | parseString :: MonadError Doc m => T.Parser r -> String -> m r 9 | parseString p s = case T.parseString p (T.Lines 0 0 0 0) s of 10 | T.Success r -> return r 11 | T.Failure d -> throwError d 12 | -------------------------------------------------------------------------------- /code/old/multityped/ll-util/src/Pretty.hs: -------------------------------------------------------------------------------- 1 | module Pretty where 2 | 3 | import Text.PrettyPrint.ANSI.Leijen hiding ((<$>)) 4 | 5 | docString :: Doc -> String 6 | docString d = displayS (renderPretty 0.4 40 (plain d)) "" 7 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/default.nix: -------------------------------------------------------------------------------- 1 | { mkDerivation, ansi-wl-pprint, base, bifunctors, containers 2 | , haskeline, lens, mtl, parsers, QuickCheck, stdenv, tasty 3 | , tasty-quickcheck, transformers, trifecta, unordered-containers 4 | }: 5 | mkDerivation { 6 | pname = "nb-modular"; 7 | version = "0.1.0.0"; 8 | src = ./.; 9 | isLibrary = true; 10 | isExecutable = true; 11 | libraryHaskellDepends = [ 12 | ansi-wl-pprint base bifunctors containers lens mtl parsers 13 | QuickCheck trifecta unordered-containers 14 | ]; 15 | executableHaskellDepends = [ 16 | ansi-wl-pprint base haskeline transformers 17 | ]; 18 | testHaskellDepends = [ 19 | base mtl QuickCheck tasty tasty-quickcheck trifecta 20 | ]; 21 | license = stdenv.lib.licenses.bsd3; 22 | } 23 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/repl/Main.hs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Control.Lens (view) 4 | 5 | import Common (repl) 6 | import Language.NB 7 | 8 | main :: IO () 9 | main = 10 | view repl languageOutput 11 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/src/Common/Error: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dalaing/little-languages/9f089f646a5344b8f7178700455a36a755d29b1f/code/old/multityped/nb-modular/src/Common/Error -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/src/Common/Error.hs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dalaing/little-languages/9f089f646a5344b8f7178700455a36a755d29b1f/code/old/multityped/nb-modular/src/Common/Error.hs -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/src/Common/Gen.hs: -------------------------------------------------------------------------------- 1 | module Common.Gen ( 2 | GenInput(..) 3 | , GenOutput(..) 4 | , mkGen 5 | ) where 6 | 7 | import Common.Gen.Type 8 | import Common.Gen.Term 9 | 10 | data GenInput ty tm = 11 | GenInput { 12 | _genTypeInput :: GenTypeInput ty 13 | , _genTermInput :: GenTermInput ty tm 14 | } 15 | 16 | instance Monoid (GenInput ty tm) where 17 | mempty = 18 | GenInput mempty mempty 19 | mappend (GenInput ty1 tm1) (GenInput ty2 tm2) = 20 | GenInput (mappend ty1 ty2) (mappend tm1 tm2) 21 | 22 | data GenOutput ty tm = 23 | GenOutput { 24 | _genTypeOutput :: GenTypeOutput ty 25 | , _genTermOutput :: GenTermOutput ty tm 26 | } 27 | 28 | mkGen :: GenInput ty tm 29 | -> GenOutput ty tm 30 | mkGen (GenInput tyi tmi) = 31 | let 32 | tyo = mkGenType tyi 33 | tmo = mkGenTerm tyo tmi 34 | in 35 | GenOutput tyo tmo 36 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/src/Common/Note.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE RankNTypes #-} 2 | {-# LANGUAGE TypeFamilies #-} 3 | module Common.Note where 4 | 5 | import Control.Lens (preview, review) 6 | import Control.Lens.Iso (Iso', iso) 7 | import Control.Lens.Prism (Prism', aside) 8 | 9 | class WithoutNote f where 10 | type Without f 11 | stripNote :: f -> Without f 12 | 13 | class WithNote f where 14 | type Note f 15 | 16 | _Note :: Prism' f (Note f, f) 17 | 18 | _WithNote :: Iso' f (Maybe (Note f), f) 19 | _WithNote = iso there back 20 | where 21 | there t = case preview _Note t of 22 | Just (l, t') -> (Just l, t') 23 | Nothing -> (Nothing, t) 24 | back (Nothing, t) = t 25 | back (Just l, t) = review _Note (l, t) 26 | 27 | withNote :: WithNote f 28 | => Prism' f a 29 | -> f 30 | -> Maybe (Maybe (Note f), a) 31 | withNote p = preview (_WithNote . aside p) 32 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/src/Common/Term/Size.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TemplateHaskell #-} 2 | {-# LANGUAGE MultiParamTypeClasses #-} 3 | {-# LANGUAGE FunctionalDependencies #-} 4 | {-# LANGUAGE FlexibleInstances #-} 5 | module Common.Term.Size ( 6 | SizeInput(..) 7 | , HasSizeInput(..) 8 | , SizeOutput(..) 9 | , HasSizeOutput(..) 10 | , mkSize 11 | ) where 12 | 13 | import Control.Lens.TH (makeClassy) 14 | 15 | import Common.Recursion 16 | 17 | data SizeInput tm = 18 | SizeInput { 19 | _sizeSteps :: [MaybeStep tm Int] 20 | } 21 | 22 | makeClassy ''SizeInput 23 | 24 | instance Monoid (SizeInput tm) where 25 | mempty = 26 | SizeInput mempty 27 | mappend (SizeInput s1) (SizeInput s2) = 28 | SizeInput (mappend s1 s2) 29 | 30 | data SizeOutput tm = 31 | SizeOutput { 32 | _size :: tm -> Int 33 | } 34 | 35 | makeClassy ''SizeOutput 36 | 37 | mkSize :: SizeInput tm 38 | -> SizeOutput tm 39 | mkSize (SizeInput s) = 40 | SizeOutput (combineMaybeSteps 0 s) 41 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/src/Common/Test.hs: -------------------------------------------------------------------------------- 1 | module Common.Test where 2 | 3 | import Test.Tasty 4 | 5 | import Common.Term 6 | import Common.Type 7 | import Common.Type.Error 8 | import Common.Test.Term 9 | import Common.Test.Type 10 | 11 | mkTests :: ( Eq ty 12 | , Show ty 13 | , Eq tm 14 | , Show tm 15 | , AsUnknownType e n 16 | ) 17 | => TypeOutput e ty 18 | -> TermOutput e ty tm 19 | -> TestTree 20 | mkTests ty tm = testGroup "tests" 21 | [ termTests tm 22 | , typeTests ty 23 | ] 24 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/src/Common/Test/Term.hs: -------------------------------------------------------------------------------- 1 | module Common.Test.Term where 2 | 3 | import Test.Tasty 4 | 5 | import Common.Type.Error 6 | import Common.Term 7 | 8 | import Common.Test.Term.Infer 9 | import Common.Test.Term.Eval 10 | import Common.Test.Term.Text 11 | 12 | termTests :: ( Eq tm 13 | , Show tm 14 | , AsUnknownType e n 15 | ) 16 | => TermOutput e ty tm 17 | -> TestTree 18 | termTests t = testGroup "term" 19 | [ inferTests t 20 | , evalTests t 21 | , textTests t 22 | ] 23 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/src/Common/Test/Term/Text.hs: -------------------------------------------------------------------------------- 1 | module Common.Test.Term.Text where 2 | 3 | import Control.Lens (view) 4 | 5 | import Test.Tasty 6 | import Test.Tasty.QuickCheck 7 | 8 | import Common.Term 9 | import Common.Term.Gen 10 | import Common.Term.Parse 11 | import Common.Term.Pretty 12 | 13 | textTests :: ( Eq tm 14 | , Show tm 15 | ) 16 | => TermOutput e ty tm 17 | -> TestTree 18 | textTests t = 19 | testGroup "text" 20 | [testProperty "roundTrip" (propRoundTrip t)] 21 | 22 | propRoundTrip :: ( Eq tm 23 | , Show tm 24 | ) 25 | => TermOutput e ty tm 26 | -> Property 27 | propRoundTrip t = 28 | forAllShrink (view genAnyTerm t) (view shrinkTerm t) $ \tm -> 29 | case roundTrip tm of 30 | Left _ -> property False 31 | Right u -> u === tm 32 | where 33 | roundTrip = 34 | view parseTermString t . 35 | view prettyTermString t 36 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/src/Common/Test/Type.hs: -------------------------------------------------------------------------------- 1 | module Common.Test.Type where 2 | 3 | import Test.Tasty 4 | 5 | import Common.Type 6 | 7 | import Common.Test.Type.Text 8 | 9 | typeTests :: ( Eq ty 10 | , Show ty 11 | ) 12 | => TypeOutput e ty 13 | -> TestTree 14 | typeTests t = testGroup "type" 15 | [textTests t] 16 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/src/Common/Test/Type/Text.hs: -------------------------------------------------------------------------------- 1 | module Common.Test.Type.Text where 2 | 3 | import Control.Lens (view) 4 | 5 | import Test.Tasty 6 | import Test.Tasty.QuickCheck 7 | 8 | import Common.Type 9 | import Common.Type.Gen 10 | import Common.Type.Parse 11 | import Common.Type.Pretty 12 | 13 | textTests :: ( Eq ty 14 | , Show ty 15 | ) 16 | => TypeOutput e ty 17 | -> TestTree 18 | textTests t = 19 | testGroup "text" 20 | [testProperty "roundTrip" (propRoundTrip t)] 21 | 22 | propRoundTrip :: ( Eq ty 23 | , Show ty 24 | ) 25 | => TypeOutput e ty 26 | -> Property 27 | propRoundTrip t = 28 | forAllShrink (view genAnyType t) (view shrinkType t) $ \tm -> 29 | case roundTrip tm of 30 | Left _ -> property False 31 | Right u -> u === tm 32 | where 33 | roundTrip = 34 | view parseTypeString t . 35 | view prettyTypeString t 36 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/src/Components/Term/Bool.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE FlexibleContexts #-} 2 | module Components.Term.Bool where 3 | 4 | import Common.Note 5 | import Common.Term 6 | import Common.Term.Eval 7 | import Common.Type.Error 8 | 9 | import Components.Term.Bool.Data 10 | import Components.Term.Bool.Gen 11 | import Components.Term.Bool.Infer 12 | import Components.Term.Bool.Eval.Value 13 | import Components.Term.Bool.Eval.SmallStep 14 | import Components.Term.Bool.Eval.BigStep 15 | import Components.Term.Bool.Parse 16 | import Components.Term.Bool.Pretty 17 | 18 | termInput :: ( Eq (Without ty) 19 | , WithoutNote ty 20 | , AsUnexpected e ty 21 | , AsExpectedEq e ty 22 | , WithBoolTerm ty tm 23 | ) 24 | => TermInput e ty tm 25 | termInput = 26 | TermInput 27 | sizeInput 28 | genTermInput 29 | inferInput 30 | (EvalInput 31 | valueInput 32 | smallStepInput 33 | bigStepInput 34 | ) 35 | parseTermInput 36 | prettyTermInput 37 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/src/Components/Term/Bool/Eval/BigStep.hs: -------------------------------------------------------------------------------- 1 | module Components.Term.Bool.Eval.BigStep where 2 | 3 | import Control.Lens (preview) 4 | 5 | import Common.Recursion (Step(..), stepFnToReader) 6 | import Common.Term.Eval.BigStep 7 | 8 | import Components.Term.Bool.Data 9 | import Components.Term.Bool.Eval.Value 10 | 11 | eIfFalse :: WithBoolTerm ty tm 12 | => (tm -> Maybe tm) 13 | -> tm 14 | -> Maybe tm 15 | eIfFalse step tm = do 16 | (t1, _, t3) <- preview _TmIf tm 17 | t1' <- step t1 18 | preview _TmFalse t1' 19 | step t3 20 | 21 | eIfTrue :: WithBoolTerm ty tm 22 | => (tm -> Maybe tm) 23 | -> tm 24 | -> Maybe tm 25 | eIfTrue step tm = do 26 | (t1, t2, _) <- preview _TmIf tm 27 | t1' <- step t1 28 | preview _TmTrue t1' 29 | step t2 30 | 31 | bigStepInput :: WithBoolTerm ty tm 32 | => BigStepInput tm 33 | bigStepInput = 34 | BigStepInput . 35 | fmap stepFnToReader $ 36 | [ SBase bv 37 | , SRecurse eIfFalse 38 | , SRecurse eIfTrue 39 | ] 40 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/src/Components/Term/Bool/Eval/Value.hs: -------------------------------------------------------------------------------- 1 | module Components.Term.Bool.Eval.Value ( 2 | bv 3 | , valueInput 4 | ) where 5 | 6 | import Data.Foldable (asum) 7 | 8 | import Control.Lens (preview, review) 9 | 10 | import Common.Recursion (Step(..), stepFnToReader) 11 | import Common.Term.Eval.Value (ValueInput(..)) 12 | 13 | import Components.Term.Bool.Data 14 | 15 | valueTmFalse :: WithBoolTerm ty tm 16 | => tm 17 | -> Maybe tm 18 | valueTmFalse = 19 | fmap (review _TmFalse) . 20 | preview _TmFalse 21 | 22 | valueTmTrue :: WithBoolTerm ty tm 23 | => tm 24 | -> Maybe tm 25 | valueTmTrue = 26 | fmap (review _TmTrue) . 27 | preview _TmTrue 28 | 29 | bv :: WithBoolTerm ty tm 30 | => tm 31 | -> Maybe tm 32 | bv tm = 33 | asum . 34 | map ($ tm) $ 35 | [ valueTmFalse 36 | , valueTmTrue 37 | ] 38 | 39 | valueInput :: WithBoolTerm ty tm 40 | => ValueInput tm 41 | valueInput = 42 | ValueInput . 43 | fmap stepFnToReader $ 44 | [SBase bv] 45 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/src/Components/Term/Nat.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE FlexibleContexts #-} 2 | module Components.Term.Nat where 3 | 4 | import Common.Note 5 | import Common.Term 6 | import Common.Term.Eval 7 | import Common.Type.Error 8 | 9 | import Components.Term.Nat.Data 10 | import Components.Term.Nat.Gen 11 | import Components.Term.Nat.Infer 12 | import Components.Term.Nat.Eval.Value 13 | import Components.Term.Nat.Eval.SmallStep 14 | import Components.Term.Nat.Eval.BigStep 15 | import Components.Term.Nat.Parse 16 | import Components.Term.Nat.Pretty 17 | 18 | termInput :: ( Eq (Without ty) 19 | , WithoutNote ty 20 | , AsUnexpected e ty 21 | , WithNatTerm ty tm 22 | ) 23 | => TermInput e ty tm 24 | termInput = 25 | TermInput 26 | sizeInput 27 | genTermInput 28 | inferInput 29 | (EvalInput 30 | valueInput 31 | smallStepInput 32 | bigStepInput 33 | ) 34 | parseTermInput 35 | prettyTermInput 36 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/src/Components/Term/Nat/Eval/Value.hs: -------------------------------------------------------------------------------- 1 | module Components.Term.Nat.Eval.Value ( 2 | nv 3 | , valueInput 4 | ) where 5 | 6 | import Data.Foldable (asum) 7 | 8 | import Control.Lens (preview, review) 9 | import Control.Monad.Reader (ReaderT(..)) 10 | 11 | import Common.Recursion (Step(..)) 12 | import Common.Term.Eval.Value (ValueInput(..)) 13 | 14 | import Components.Term.Nat.Data 15 | 16 | valueTmZero :: WithNatTerm ty tm 17 | => tm 18 | -> Maybe tm 19 | valueTmZero = 20 | fmap (review _TmZero) . 21 | preview _TmZero 22 | 23 | valueTmSucc :: WithNatTerm ty tm 24 | => tm 25 | -> Maybe tm 26 | valueTmSucc tm = do 27 | n <- preview _TmSucc tm 28 | -- this is the strict version 29 | n' <- nv n 30 | return $ review _TmSucc n' 31 | 32 | nv :: WithNatTerm ty tm 33 | => tm 34 | -> Maybe tm 35 | nv tm = 36 | asum . 37 | map ($ tm) $ 38 | [ valueTmZero 39 | , valueTmSucc 40 | ] 41 | 42 | valueInput :: WithNatTerm ty tm 43 | => ValueInput tm 44 | valueInput = 45 | ValueInput [SBase $ ReaderT nv] 46 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/src/Components/Term/NatBool/Eval/Value.hs: -------------------------------------------------------------------------------- 1 | module Components.Term.NatBool.Eval.Value ( 2 | valueInput 3 | ) where 4 | 5 | import Common.Term.Eval.Value (ValueInput(..)) 6 | 7 | import Components.Term.NatBool.Data 8 | 9 | valueInput :: WithNatBoolTerm ty tm 10 | => ValueInput tm 11 | valueInput = 12 | mempty 13 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/src/Components/Term/NatBool/Parse.hs: -------------------------------------------------------------------------------- 1 | module Components.Term.NatBool.Parse where 2 | 3 | import Control.Lens (review) 4 | 5 | import Text.Parser.Combinators 6 | import Text.Parser.Token 7 | 8 | import Common.Recursion 9 | import Common.Term.Parse (ParseTermInput(..)) 10 | 11 | import Components.Term.NatBool.Data 12 | 13 | parseTmIsZero :: ( WithNatBoolTerm ty tm 14 | , TokenParsing m 15 | ) 16 | => m tm 17 | -> m tm 18 | parseTmIsZero parseTerm = 19 | fmap (review _TmIsZero) parseTmIsZero' 20 | where 21 | parseTmIsZero' = 22 | id <$ 23 | symbol "isZero" <*> 24 | parseTerm 25 | "isZero" 26 | 27 | parseTermInput :: WithNatBoolTerm ty tm 28 | => ParseTermInput tm 29 | parseTermInput = 30 | ParseTermInput 31 | [SRecurse parseTmIsZero] 32 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/src/Components/Term/NatBool/Pretty.hs: -------------------------------------------------------------------------------- 1 | module Components.Term.NatBool.Pretty where 2 | 3 | import Control.Lens (preview) 4 | 5 | import Text.PrettyPrint.ANSI.Leijen 6 | 7 | import Common.Recursion 8 | import Common.Term.Pretty (PrettyTermInput(..)) 9 | 10 | import Components.Term.NatBool.Data 11 | 12 | prettyTmIsZero :: WithNatBoolTerm ty tm 13 | => (tm -> Doc) 14 | -> tm 15 | -> Maybe Doc 16 | prettyTmIsZero prettyTerm = 17 | fmap prettyTmIsZero' . 18 | preview _TmIsZero 19 | where 20 | prettyTmIsZero' t = 21 | text "isZero" <+> prettyTerm t 22 | 23 | prettyTermInput :: WithNatBoolTerm ty tm 24 | => PrettyTermInput tm 25 | prettyTermInput = 26 | PrettyTermInput 27 | [MSRecurse prettyTmIsZero] 28 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/src/Components/Term/Note.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE FlexibleContexts #-} 2 | module Components.Term.Note where 3 | 4 | import Text.Trifecta.Rendering (Span) 5 | 6 | import Common.Term 7 | import Common.Term.Eval 8 | 9 | import Components.Type.Note.Data 10 | 11 | import Components.Term.Note.Data 12 | import Components.Term.Note.Gen 13 | import Components.Term.Note.Infer 14 | import Components.Term.Note.Eval.Value 15 | import Components.Term.Note.Eval.SmallStep 16 | import Components.Term.Note.Eval.BigStep 17 | import Components.Term.Note.Parse 18 | import Components.Term.Note.Pretty 19 | 20 | termInput :: ( WithNoteType Span ty 21 | , WithNoteTerm Span ty tm 22 | ) 23 | => TermInput e ty tm 24 | termInput = 25 | TermInput 26 | sizeInput 27 | genTermInput 28 | inferInput 29 | (EvalInput 30 | valueInput 31 | smallStepInput 32 | bigStepInput 33 | ) 34 | parseTermInput 35 | prettyTermInput 36 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/src/Components/Term/Note/Eval/BigStep.hs: -------------------------------------------------------------------------------- 1 | module Components.Term.Note.Eval.BigStep where 2 | 3 | import Control.Lens (preview) 4 | 5 | import Common.Recursion (Step(..), stepFnToReader) 6 | import Common.Term.Eval.BigStep 7 | 8 | import Components.Term.Note.Data 9 | 10 | eNoted :: WithNoteTerm n ty tm 11 | => (tm -> Maybe tm) 12 | -> tm 13 | -> Maybe tm 14 | eNoted step tm = do 15 | (_, t) <- preview _TmNoted tm 16 | step t 17 | 18 | bigStepInput :: WithNoteTerm n ty tm 19 | => BigStepInput tm 20 | bigStepInput = 21 | BigStepInput . 22 | fmap stepFnToReader $ 23 | [ SRecurse eNoted ] 24 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/src/Components/Term/Note/Eval/SmallStep.hs: -------------------------------------------------------------------------------- 1 | module Components.Term.Note.Eval.SmallStep where 2 | 3 | import Control.Lens (preview) 4 | 5 | import Common.Recursion (Step(..), stepFnToReader) 6 | import Common.Term.Eval.SmallStep 7 | 8 | import Components.Term.Note.Data 9 | 10 | eNoted :: WithNoteTerm n ty tm 11 | => (tm -> Maybe tm) 12 | -> tm 13 | -> Maybe tm 14 | eNoted step tm = do 15 | (_, t) <- preview _TmNoted tm 16 | step t 17 | 18 | smallStepInput :: WithNoteTerm n ty tm 19 | => SmallStepInput tm 20 | smallStepInput = 21 | SmallStepInput . 22 | fmap stepFnToReader $ 23 | [ SRecurse eNoted ] 24 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/src/Components/Term/Note/Eval/Value.hs: -------------------------------------------------------------------------------- 1 | module Components.Term.Note.Eval.Value ( 2 | valueInput 3 | ) where 4 | 5 | import Common.Term.Eval.Value (ValueInput(..)) 6 | 7 | import Components.Term.Note.Data 8 | 9 | valueInput :: WithNoteTerm n ty tm 10 | => ValueInput tm 11 | valueInput = 12 | mempty 13 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/src/Components/Term/Note/Gen.hs: -------------------------------------------------------------------------------- 1 | module Components.Term.Note.Gen where 2 | 3 | import Common.Term.Gen 4 | 5 | import Components.Term.Note.Data 6 | 7 | genTermInput :: WithNoteTerm n ty tm 8 | => GenTermInput ty tm 9 | genTermInput = mempty 10 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/src/Components/Term/Note/Parse.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE FlexibleContexts #-} 2 | module Components.Term.Note.Parse where 3 | 4 | import Control.Lens (review) 5 | 6 | import Text.Trifecta.Combinators (DeltaParsing, spanned) 7 | import Text.Trifecta.Rendering (Span, Spanned(..)) 8 | 9 | import Common.Recursion 10 | import Common.Term.Parse (ParseTermInput(..)) 11 | 12 | import Components.Term.Note.Data 13 | 14 | parseTmNote :: ( WithNoteTerm Span ty tm 15 | , Monad m 16 | , DeltaParsing m 17 | ) 18 | => m tm 19 | -> m tm 20 | parseTmNote parseTerm = do 21 | (t :~ n) <- spanned parseTerm 22 | return $ review _TmNoted (n, t) 23 | 24 | 25 | parseTermInput :: WithNoteTerm Span ty tm 26 | => ParseTermInput tm 27 | parseTermInput = 28 | ParseTermInput 29 | [SRecurse parseTmNote] 30 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/src/Components/Term/Note/Pretty.hs: -------------------------------------------------------------------------------- 1 | module Components.Term.Note.Pretty where 2 | 3 | import Control.Lens (preview) 4 | 5 | import Text.PrettyPrint.ANSI.Leijen 6 | 7 | import Common.Recursion 8 | import Common.Term.Pretty (PrettyTermInput(..)) 9 | 10 | import Components.Term.Note.Data 11 | 12 | prettyTmNoted :: WithNoteTerm n ty tm 13 | => (tm -> Doc) 14 | -> tm 15 | -> Maybe Doc 16 | prettyTmNoted prettyTerm = 17 | fmap prettyTmNoted' . 18 | preview _TmNoted 19 | where 20 | prettyTmNoted' (_, t) = 21 | prettyTerm t 22 | 23 | prettyTermInput :: WithNoteTerm n ty tm 24 | => PrettyTermInput tm 25 | prettyTermInput = 26 | PrettyTermInput 27 | [MSRecurse prettyTmNoted] 28 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/src/Components/Type/Bool.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE FlexibleContexts #-} 2 | module Components.Type.Bool where 3 | 4 | import Common.Type 5 | 6 | import Components.Type.Bool.Data 7 | import Components.Type.Bool.Gen 8 | import Components.Type.Bool.Parse 9 | import Components.Type.Bool.Pretty 10 | 11 | typeInput :: WithBoolType ty 12 | => TypeInput e ty 13 | typeInput = 14 | TypeInput 15 | genTypeInput 16 | parseTypeInput 17 | prettyTypeInput 18 | mempty 19 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/src/Components/Type/Bool/Data.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TemplateHaskell #-} 2 | {-# LANGUAGE MultiParamTypeClasses #-} 3 | {-# LANGUAGE FunctionalDependencies #-} 4 | {-# LANGUAGE FlexibleInstances #-} 5 | {-# LANGUAGE TypeFamilies #-} 6 | {-# LANGUAGE ConstraintKinds #-} 7 | module Components.Type.Bool.Data where 8 | 9 | import Control.Lens.TH (makeClassyPrisms) 10 | 11 | import Common.Note 12 | 13 | data BoolType = 14 | TyBool 15 | deriving (Eq, Ord, Show) 16 | 17 | makeClassyPrisms ''BoolType 18 | 19 | type WithBoolType ty = AsBoolType ty 20 | 21 | instance WithoutNote BoolType where 22 | type Without BoolType = BoolType 23 | stripNote = id 24 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/src/Components/Type/Bool/Gen.hs: -------------------------------------------------------------------------------- 1 | module Components.Type.Bool.Gen where 2 | 3 | import Control.Lens (preview, review) 4 | import Control.Lens.Prism (isn't) 5 | 6 | import Test.QuickCheck (Gen) 7 | 8 | import Common.Type.Gen 9 | 10 | import Components.Type.Bool.Data 11 | 12 | genTyBool :: WithBoolType ty 13 | => Gen ty 14 | genTyBool = pure (review _TyBool ()) 15 | 16 | genNotTyBool :: WithBoolType ty 17 | => ty 18 | -> Maybe (Gen ty) 19 | genNotTyBool ty 20 | | isn't _TyBool ty = Just genTyBool 21 | | otherwise = Nothing 22 | 23 | shrinkTyBool :: WithBoolType ty 24 | => ty 25 | -> Maybe [ty] 26 | shrinkTyBool = 27 | fmap (const []) . 28 | preview _TyBool 29 | 30 | genTypeInput :: WithBoolType ty 31 | => GenTypeInput ty 32 | genTypeInput = 33 | GenTypeInput 34 | [TyBase genTyBool] 35 | [NTyBase genNotTyBool] 36 | [ShrTyBase shrinkTyBool] 37 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/src/Components/Type/Bool/Parse.hs: -------------------------------------------------------------------------------- 1 | module Components.Type.Bool.Parse where 2 | 3 | import Control.Lens (review) 4 | 5 | import Text.Parser.Combinators 6 | import Text.Parser.Token 7 | 8 | import Common.Recursion 9 | import Common.Type.Parse 10 | 11 | import Components.Type.Bool.Data 12 | 13 | parseTyBool :: ( WithBoolType ty 14 | , TokenParsing m 15 | ) 16 | => m ty 17 | parseTyBool = 18 | review _TyBool () <$ 19 | symbol "Bool" 20 | "Bool" 21 | 22 | parseTypeInput :: WithBoolType ty 23 | => ParseTypeInput ty 24 | parseTypeInput = 25 | ParseTypeInput 26 | [SBase parseTyBool] 27 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/src/Components/Type/Bool/Pretty.hs: -------------------------------------------------------------------------------- 1 | module Components.Type.Bool.Pretty where 2 | 3 | import Control.Lens (preview) 4 | 5 | import Text.PrettyPrint.ANSI.Leijen 6 | 7 | import Common.Recursion 8 | import Common.Type.Pretty 9 | 10 | import Components.Type.Bool.Data 11 | 12 | prettyTyBool :: WithBoolType ty 13 | => ty 14 | -> Maybe Doc 15 | prettyTyBool = 16 | fmap (const . text $ "Bool") . 17 | preview _TyBool 18 | 19 | prettyTypeInput :: WithBoolType ty 20 | => PrettyTypeInput ty 21 | prettyTypeInput = 22 | PrettyTypeInput 23 | [ MSBase prettyTyBool ] 24 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/src/Components/Type/Nat.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE FlexibleContexts #-} 2 | module Components.Type.Nat where 3 | 4 | import Common.Type 5 | 6 | import Components.Type.Nat.Data 7 | import Components.Type.Nat.Gen 8 | import Components.Type.Nat.Parse 9 | import Components.Type.Nat.Pretty 10 | 11 | typeInput :: WithNatType ty 12 | => TypeInput e ty 13 | typeInput = 14 | TypeInput 15 | genTypeInput 16 | parseTypeInput 17 | prettyTypeInput 18 | mempty 19 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/src/Components/Type/Nat/Data.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TemplateHaskell #-} 2 | {-# LANGUAGE MultiParamTypeClasses #-} 3 | {-# LANGUAGE FunctionalDependencies #-} 4 | {-# LANGUAGE FlexibleInstances #-} 5 | {-# LANGUAGE TypeFamilies #-} 6 | {-# LANGUAGE ConstraintKinds #-} 7 | module Components.Type.Nat.Data where 8 | 9 | import Control.Lens.TH (makeClassyPrisms) 10 | 11 | import Common.Note 12 | 13 | data NatType = 14 | TyNat 15 | deriving (Eq, Ord, Show) 16 | 17 | makeClassyPrisms ''NatType 18 | 19 | type WithNatType ty = AsNatType ty 20 | 21 | instance WithoutNote NatType where 22 | type Without NatType = NatType 23 | stripNote = id 24 | 25 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/src/Components/Type/Nat/Gen.hs: -------------------------------------------------------------------------------- 1 | module Components.Type.Nat.Gen where 2 | 3 | import Control.Lens (preview, review) 4 | import Control.Lens.Prism (isn't) 5 | 6 | import Test.QuickCheck (Gen) 7 | 8 | import Common.Type.Gen 9 | 10 | import Components.Type.Nat.Data 11 | 12 | genTyNat :: WithNatType ty 13 | => Gen ty 14 | genTyNat = pure (review _TyNat ()) 15 | 16 | genNotTyNat :: WithNatType ty 17 | => ty 18 | -> Maybe (Gen ty) 19 | genNotTyNat ty 20 | | isn't _TyNat ty = Just genTyNat 21 | | otherwise = Nothing 22 | 23 | shrinkTyNat :: WithNatType ty 24 | => ty 25 | -> Maybe [ty] 26 | shrinkTyNat = 27 | fmap (const []) . 28 | preview _TyNat 29 | 30 | genTypeInput :: WithNatType ty 31 | => GenTypeInput ty 32 | genTypeInput = 33 | GenTypeInput 34 | [TyBase genTyNat] 35 | [NTyBase genNotTyNat] 36 | [ShrTyBase shrinkTyNat] 37 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/src/Components/Type/Nat/Parse.hs: -------------------------------------------------------------------------------- 1 | module Components.Type.Nat.Parse where 2 | 3 | import Control.Lens (review) 4 | 5 | import Text.Parser.Combinators 6 | import Text.Parser.Token 7 | 8 | import Common.Recursion 9 | import Common.Type.Parse 10 | 11 | import Components.Type.Nat.Data 12 | 13 | parseTyNat :: ( WithNatType ty 14 | , TokenParsing m 15 | ) 16 | => m ty 17 | parseTyNat = 18 | review _TyNat () <$ 19 | symbol "Nat" 20 | "Nat" 21 | 22 | parseTypeInput :: WithNatType ty 23 | => ParseTypeInput ty 24 | parseTypeInput = 25 | ParseTypeInput 26 | [SBase parseTyNat] 27 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/src/Components/Type/Nat/Pretty.hs: -------------------------------------------------------------------------------- 1 | module Components.Type.Nat.Pretty where 2 | 3 | import Control.Lens (preview) 4 | 5 | import Text.PrettyPrint.ANSI.Leijen 6 | 7 | import Common.Recursion 8 | import Common.Type.Pretty 9 | 10 | import Components.Type.Nat.Data 11 | 12 | prettyTyNat :: WithNatType ty 13 | => ty 14 | -> Maybe Doc 15 | prettyTyNat = 16 | fmap (const . text $ "Nat") . 17 | preview _TyNat 18 | 19 | prettyTypeInput :: WithNatType ty 20 | => PrettyTypeInput ty 21 | prettyTypeInput = 22 | PrettyTypeInput 23 | [ MSBase prettyTyNat ] 24 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/src/Components/Type/Note.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE FlexibleContexts #-} 2 | module Components.Type.Note where 3 | 4 | import Text.Trifecta.Rendering (Span) 5 | 6 | import Common.Type 7 | 8 | import Components.Type.Note.Data 9 | import Components.Type.Note.Gen 10 | import Components.Type.Note.Parse 11 | import Components.Type.Note.Pretty 12 | 13 | typeInput :: WithNoteType Span ty 14 | => TypeInput e ty 15 | typeInput = 16 | TypeInput 17 | genTypeInput 18 | parseTypeInput 19 | prettyTypeInput 20 | mempty 21 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/src/Components/Type/Note/Data.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TemplateHaskell #-} 2 | {-# LANGUAGE MultiParamTypeClasses #-} 3 | {-# LANGUAGE FunctionalDependencies #-} 4 | {-# LANGUAGE FlexibleInstances #-} 5 | {-# LANGUAGE DeriveFunctor #-} 6 | {-# LANGUAGE DeriveFoldable #-} 7 | {-# LANGUAGE DeriveTraversable #-} 8 | {-# LANGUAGE ConstraintKinds #-} 9 | {-# LANGUAGE TypeFamilies #-} 10 | module Components.Type.Note.Data where 11 | 12 | import Data.Bifunctor 13 | 14 | import Control.Lens.TH (makeClassyPrisms) 15 | 16 | import Common.Note 17 | 18 | data NoteType n f = 19 | TyNoted n f 20 | deriving (Eq, Ord, Show, Functor, Foldable, Traversable) 21 | 22 | makeClassyPrisms ''NoteType 23 | 24 | type WithNoteType n ty = AsNoteType ty n ty 25 | 26 | instance Bifunctor NoteType where 27 | bimap g h (TyNoted n f) = TyNoted (g n) (h f) 28 | 29 | instance WithoutNote f => WithoutNote (NoteType n f) where 30 | type Without (NoteType n f) = Without f 31 | stripNote (TyNoted _ f) = stripNote f 32 | 33 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/src/Components/Type/Note/Gen.hs: -------------------------------------------------------------------------------- 1 | module Components.Type.Note.Gen where 2 | 3 | import Control.Lens (preview) 4 | 5 | import Test.QuickCheck (Gen) 6 | 7 | import Common.Type.Gen 8 | 9 | import Components.Type.Note.Data 10 | 11 | genNotTyNote :: WithNoteType n ty 12 | => (ty -> Gen ty) 13 | -> ty 14 | -> Maybe (Gen ty) 15 | genNotTyNote genNotType = 16 | fmap (genNotType . snd) . 17 | preview _TyNoted 18 | 19 | shrTyNote :: WithNoteType n ty 20 | => ty 21 | -> Maybe [ty] 22 | shrTyNote = 23 | fmap (pure . snd) . 24 | preview _TyNoted 25 | 26 | genTypeInput :: WithNoteType n ty 27 | => GenTypeInput ty 28 | genTypeInput = 29 | GenTypeInput 30 | [] 31 | [NTyRecurse $ const genNotTyNote] 32 | [ShrTyBase shrTyNote] 33 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/src/Components/Type/Note/Parse.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE FlexibleContexts #-} 2 | module Components.Type.Note.Parse where 3 | 4 | import Control.Lens (review) 5 | 6 | import Text.Trifecta.Combinators (DeltaParsing, spanned) 7 | import Text.Trifecta.Rendering (Span, Spanned(..)) 8 | 9 | import Common.Recursion 10 | import Common.Type.Parse 11 | 12 | import Components.Type.Note.Data 13 | 14 | parseTyNote :: ( WithNoteType Span ty 15 | , Monad m 16 | , DeltaParsing m 17 | ) 18 | => m ty 19 | -> m ty 20 | parseTyNote parseType' = do 21 | (t :~ n) <- spanned parseType' 22 | return $ review _TyNoted (n, t) 23 | 24 | 25 | parseTypeInput :: WithNoteType Span ty 26 | => ParseTypeInput ty 27 | parseTypeInput = 28 | ParseTypeInput 29 | [SRecurse parseTyNote] 30 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/src/Components/Type/Note/Pretty.hs: -------------------------------------------------------------------------------- 1 | module Components.Type.Note.Pretty where 2 | 3 | import Control.Lens (preview) 4 | 5 | import Text.PrettyPrint.ANSI.Leijen 6 | 7 | import Common.Recursion 8 | import Common.Type.Pretty (PrettyTypeInput(..)) 9 | 10 | import Components.Type.Note.Data 11 | 12 | prettyTyNote :: WithNoteType n ty 13 | => (ty -> Doc) 14 | -> ty 15 | -> Maybe Doc 16 | prettyTyNote prettyType = 17 | fmap prettyTyNote' . 18 | preview _TyNoted 19 | where 20 | prettyTyNote' (_, ty) = 21 | prettyType ty 22 | 23 | prettyTypeInput :: WithNoteType n ty 24 | => PrettyTypeInput ty 25 | prettyTypeInput = 26 | PrettyTypeInput 27 | [ MSRecurse prettyTyNote ] 28 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/src/Language/NB.hs: -------------------------------------------------------------------------------- 1 | module Language.NB where 2 | 3 | import Text.Trifecta.Rendering (Span) 4 | 5 | import Common (LanguageInput(..), LanguageOutput(..), mkLanguage) 6 | 7 | import Language.NB.Term 8 | import Language.NB.Type 9 | import Language.NB.Type.Error 10 | 11 | languageInput :: LanguageInput (Error Span (Type Span)) (Type Span) (Term (Type Span) Span) 12 | languageInput = 13 | LanguageInput typeInput termInput 14 | 15 | languageOutput :: LanguageOutput (Error Span (Type Span)) (Type Span) (Term (Type Span) Span) 16 | languageOutput = 17 | mkLanguage languageInput 18 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/tests/Test.hs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Control.Lens (view) 4 | import Test.Tasty 5 | 6 | import Common (tests) 7 | import Language.NB 8 | 9 | main :: IO () 10 | main = 11 | defaultMain . 12 | view tests $ 13 | languageOutput 14 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/tests/Test/Term.hs: -------------------------------------------------------------------------------- 1 | module Test.Term where 2 | 3 | import Test.Tasty 4 | 5 | import Test.Term.Text (textTests) 6 | import Test.Term.Eval (evalTests) 7 | 8 | termTests :: TestTree 9 | termTests = testGroup "term" [ 10 | textTests 11 | , evalTests 12 | ] 13 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/tests/Test/Term/Text.hs: -------------------------------------------------------------------------------- 1 | module Test.Term.Text where 2 | 3 | import Test.Tasty 4 | import Test.Tasty.QuickCheck 5 | 6 | import Term.Gen 7 | import Term.Parse 8 | import Term.Pretty 9 | 10 | textTests :: TestTree 11 | textTests = 12 | testGroup "text" [ 13 | testProperty "roundTrip" propRoundTrip 14 | ] 15 | 16 | propRoundTrip :: AnyTerm 17 | -> Property 18 | propRoundTrip t = 19 | case roundTrip t of 20 | Left _ -> property False 21 | Right u -> u === t 22 | where 23 | roundTrip = 24 | fmap AnyTerm . 25 | parseTermString . 26 | prettyTermString . 27 | getAnyTerm 28 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/tests/Test/Type.hs: -------------------------------------------------------------------------------- 1 | module Test.Type ( 2 | typeTests 3 | ) where 4 | 5 | import Test.Tasty 6 | 7 | import Test.Type.Text (textTests) 8 | import Test.Type.Infer (inferTests) 9 | import Test.Type.Safety (safetyTests) 10 | 11 | typeTests :: TestTree 12 | typeTests = testGroup "type" [ 13 | textTests 14 | , inferTests 15 | , safetyTests 16 | ] 17 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/tests/Test/Type/Infer.hs: -------------------------------------------------------------------------------- 1 | module Test.Type.Infer ( 2 | inferTests 3 | ) where 4 | 5 | import Test.Tasty 6 | import Test.Tasty.QuickCheck 7 | 8 | import Control.Monad.Except (runExcept) 9 | 10 | import Term.Gen 11 | import Type.Infer 12 | 13 | inferTests :: TestTree 14 | inferTests = testGroup "infer" [ 15 | testProperty "wellTypedInfer" propWellTypedInfer 16 | , testProperty "illTypedInfer" propIllTypedInfer 17 | ] 18 | 19 | isRight :: Either a b -> Bool 20 | isRight (Right _) = True 21 | isRight _ = False 22 | 23 | isLeft :: Either a b -> Bool 24 | isLeft (Left _) = True 25 | isLeft _ = False 26 | 27 | propWellTypedInfer :: WellTypedTerm -> Bool 28 | propWellTypedInfer (WellTypedTerm t) = 29 | isRight . runExcept . infer $ t 30 | 31 | propIllTypedInfer :: IllTypedTerm -> Bool 32 | propIllTypedInfer (IllTypedTerm t) = 33 | isLeft . runExcept . infer $ t 34 | -------------------------------------------------------------------------------- /code/old/multityped/nb-modular/tests/Test/Type/Text.hs: -------------------------------------------------------------------------------- 1 | module Test.Type.Text ( 2 | textTests 3 | ) where 4 | 5 | import Test.Tasty 6 | import Test.Tasty.QuickCheck 7 | 8 | import Type.Gen 9 | import Type.Parse 10 | import Type.Pretty 11 | 12 | textTests :: TestTree 13 | textTests = 14 | testGroup "text" [ 15 | testProperty "roundTrip" propRoundTrip 16 | ] 17 | 18 | propRoundTrip :: AnyType 19 | -> Property 20 | propRoundTrip t = 21 | case roundTrip t of 22 | Left _ -> property False 23 | Right u -> u === t 24 | where 25 | roundTrip = 26 | fmap AnyType . 27 | parseTypeString . 28 | prettyTypeString . 29 | getAnyType 30 | -------------------------------------------------------------------------------- /code/old/multityped/nb-srcloc/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /code/old/multityped/nb-srcloc/default.nix: -------------------------------------------------------------------------------- 1 | { mkDerivation, ansi-wl-pprint, base, lens, mtl, parsers 2 | , QuickCheck, stdenv, tasty, tasty-quickcheck, trifecta 3 | , unordered-containers 4 | }: 5 | mkDerivation { 6 | pname = "nb-srcloc"; 7 | version = "0.1.0.0"; 8 | src = ./.; 9 | libraryHaskellDepends = [ 10 | ansi-wl-pprint base lens mtl parsers QuickCheck trifecta 11 | unordered-containers 12 | ]; 13 | testHaskellDepends = [ 14 | base mtl QuickCheck tasty tasty-quickcheck trifecta 15 | ]; 16 | license = stdenv.lib.licenses.bsd3; 17 | } 18 | -------------------------------------------------------------------------------- /code/old/multityped/nb-srcloc/repl/Main.hs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Control.Monad.IO.Class 4 | import System.Console.Haskeline 5 | 6 | import Text.PrettyPrint.ANSI.Leijen (putDoc, (<>), line) 7 | 8 | import UI 9 | 10 | main :: IO () 11 | main = runInputT defaultSettings loop 12 | where 13 | loop :: InputT IO () 14 | loop = do 15 | i <- getInputLine "> " 16 | case i of 17 | Nothing -> return () 18 | Just "quit" -> return () 19 | Just i' -> do 20 | liftIO . putDoc . (<> line) . parseAndEval $ i' 21 | loop 22 | -------------------------------------------------------------------------------- /code/old/multityped/nb-srcloc/shell.nix: -------------------------------------------------------------------------------- 1 | { nixpkgs ? import {}, compiler ? "default" }: 2 | 3 | let 4 | 5 | inherit (nixpkgs) pkgs; 6 | 7 | f = { mkDerivation, ansi-wl-pprint, base, lens, mtl, parsers 8 | , QuickCheck, stdenv, tasty, tasty-quickcheck, trifecta 9 | , unordered-containers 10 | }: 11 | mkDerivation { 12 | pname = "nb-srcloc"; 13 | version = "0.1.0.0"; 14 | src = ./.; 15 | libraryHaskellDepends = [ 16 | ansi-wl-pprint base lens mtl parsers QuickCheck trifecta 17 | unordered-containers 18 | ]; 19 | testHaskellDepends = [ 20 | base mtl QuickCheck tasty tasty-quickcheck trifecta 21 | ]; 22 | license = stdenv.lib.licenses.bsd3; 23 | }; 24 | 25 | haskellPackages = if compiler == "default" 26 | then pkgs.haskellPackages 27 | else pkgs.haskell.packages.${compiler}; 28 | 29 | drv = haskellPackages.callPackage f {}; 30 | 31 | in 32 | 33 | if pkgs.lib.inNixShell then drv.env else drv 34 | -------------------------------------------------------------------------------- /code/old/multityped/nb-srcloc/src/Loc.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE MultiParamTypeClasses #-} 2 | {-# LANGUAGE RankNTypes #-} 3 | module Loc where 4 | 5 | import Control.Lens (preview, review) 6 | import Control.Lens.Iso (Iso', iso) 7 | import Control.Lens.Prism (Prism', aside) 8 | 9 | class WithLoc f where 10 | _Loc :: Prism' (f l) (l, f l) 11 | 12 | stripLoc :: f l -> f () 13 | 14 | _WithLoc :: Iso' (f l) (Maybe l, f l) 15 | _WithLoc = iso there back 16 | where 17 | there t = case preview _Loc t of 18 | Just (l, t') -> (Just l, t') 19 | Nothing -> (Nothing, t) 20 | back (Nothing, t) = t 21 | back (Just l, t) = review _Loc (l, t) 22 | 23 | withLoc :: WithLoc f => Prism' (f l) a -> f l -> Maybe (Maybe l, a) 24 | withLoc p = preview (_WithLoc . aside p) 25 | -------------------------------------------------------------------------------- /code/old/multityped/nb-srcloc/src/Term/Eval/Value.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE FlexibleContexts #-} 2 | module Term.Eval.Value where 3 | 4 | import Control.Applicative ((<|>)) 5 | 6 | import Term 7 | 8 | bv :: Term l 9 | -> Maybe (Term l) 10 | bv TmFalse = Just TmFalse 11 | bv TmTrue = Just TmTrue 12 | bv _ = Nothing 13 | 14 | nv :: Term l 15 | -> Maybe (Term l) 16 | nv TmZero = Just TmZero 17 | nv (TmSucc t) = TmSucc <$> nv t 18 | nv _ = Nothing 19 | 20 | value :: Term l 21 | -> Maybe (Term l) 22 | value t = 23 | bv t <|> nv t 24 | -------------------------------------------------------------------------------- /code/old/multityped/nb-srcloc/src/Type.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TemplateHaskell #-} 2 | {-# LANGUAGE MultiParamTypeClasses #-} 3 | {-# LANGUAGE FunctionalDependencies #-} 4 | {-# LANGUAGE FlexibleInstances #-} 5 | module Type where 6 | 7 | import Control.Lens.TH 8 | 9 | import Loc 10 | 11 | data Type l = 12 | TyBool 13 | | TyNat 14 | | TyLoc l (Type l) 15 | deriving (Eq, Ord, Show) 16 | 17 | makeClassyPrisms ''Type 18 | 19 | instance WithLoc Type where 20 | _Loc = _TyLoc 21 | 22 | stripLoc TyBool = TyBool 23 | stripLoc TyNat = TyNat 24 | stripLoc (TyLoc _ t) = stripLoc t 25 | -------------------------------------------------------------------------------- /code/old/multityped/nb-srcloc/src/Type/Gen.hs: -------------------------------------------------------------------------------- 1 | module Type.Gen where 2 | 3 | import Text.Trifecta.Rendering (Span) 4 | 5 | import Test.QuickCheck (Gen, Arbitrary(..), elements) 6 | 7 | import Loc 8 | import Type 9 | 10 | genType :: Gen (Type l) 11 | genType = elements [TyBool, TyNat] 12 | 13 | genNotType :: Type l -> Gen (Type l) 14 | genNotType TyBool = return TyNat 15 | genNotType TyNat = return TyBool 16 | genNotType (TyLoc _ t) = genNotType t 17 | 18 | shrinkType :: Type l -> [Type l] 19 | shrinkType = const [] 20 | 21 | newtype AnyType = AnyType { getAnyType :: Type Span } 22 | deriving (Show) 23 | 24 | instance Eq AnyType where 25 | AnyType x == AnyType y = 26 | stripLoc x == stripLoc y 27 | 28 | instance Ord AnyType where 29 | compare (AnyType x) (AnyType y) = 30 | compare (stripLoc x) (stripLoc y) 31 | 32 | instance Arbitrary AnyType where 33 | arbitrary = AnyType <$> genType 34 | shrink = fmap AnyType . shrinkType . getAnyType 35 | -------------------------------------------------------------------------------- /code/old/multityped/nb-srcloc/src/Type/Pretty.hs: -------------------------------------------------------------------------------- 1 | module Type.Pretty where 2 | 3 | import Control.Lens (preview) 4 | import Data.Foldable (asum) 5 | import Data.Maybe (fromMaybe) 6 | 7 | import Text.PrettyPrint.ANSI.Leijen 8 | 9 | import Type 10 | 11 | printTyBool :: Type l 12 | -> Maybe Doc 13 | printTyBool = 14 | fmap (const . text $ "Bool") . 15 | preview _TyBool 16 | 17 | printTyNat :: Type l 18 | -> Maybe Doc 19 | printTyNat = 20 | fmap (const . text $ "Nat") . 21 | preview _TyNat 22 | 23 | printTyLoc :: (Type l -> Doc) 24 | -> Type l 25 | -> Maybe Doc 26 | printTyLoc pr = 27 | fmap (pr . snd) . 28 | preview _TyLoc 29 | 30 | prettyType :: Type l 31 | -> Doc 32 | prettyType t = 33 | fromMaybe empty . 34 | asum . 35 | map ($ t) $ [ 36 | printTyBool 37 | , printTyNat 38 | , printTyLoc prettyType 39 | ] 40 | 41 | docString :: Doc 42 | -> String 43 | docString d = 44 | displayS (renderPretty 0.4 40 (plain d)) "" 45 | 46 | prettyTypeString :: Type l 47 | -> String 48 | prettyTypeString = 49 | docString . 50 | prettyType 51 | -------------------------------------------------------------------------------- /code/old/multityped/nb-srcloc/src/UI.hs: -------------------------------------------------------------------------------- 1 | module UI where 2 | 3 | import Control.Monad.Except 4 | import Text.PrettyPrint.ANSI.Leijen (Doc, (<+>), text) 5 | 6 | import Term.Parse 7 | import Term.Pretty 8 | import Term.Eval.SmallStep 9 | 10 | import Type.Pretty 11 | import Type.Error.Message 12 | import Type.Infer 13 | 14 | parseAndEval :: String -> Doc 15 | parseAndEval s = 16 | case parseTermString s of 17 | Left e -> e 18 | Right tm -> case (runExcept . infer) tm of 19 | Left e -> prettyError e 20 | Right ty -> printTerm (sEval tm) <+> text ":" <+> prettyType ty 21 | -------------------------------------------------------------------------------- /code/old/multityped/nb-srcloc/tests/Test.hs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Test.Tasty 4 | 5 | import Test.Term (termTests) 6 | import Test.Type (typeTests) 7 | 8 | main :: IO () 9 | main = defaultMain tests 10 | 11 | tests :: TestTree 12 | tests = testGroup "Tests" [ 13 | termTests 14 | , typeTests 15 | ] 16 | -------------------------------------------------------------------------------- /code/old/multityped/nb-srcloc/tests/Test/Term.hs: -------------------------------------------------------------------------------- 1 | module Test.Term where 2 | 3 | import Test.Tasty 4 | 5 | import Test.Term.Text (textTests) 6 | import Test.Term.Eval (evalTests) 7 | 8 | termTests :: TestTree 9 | termTests = testGroup "term" [ 10 | textTests 11 | , evalTests 12 | ] 13 | -------------------------------------------------------------------------------- /code/old/multityped/nb-srcloc/tests/Test/Term/Text.hs: -------------------------------------------------------------------------------- 1 | module Test.Term.Text where 2 | 3 | import Test.Tasty 4 | import Test.Tasty.QuickCheck 5 | 6 | import Term.Gen 7 | import Term.Parse 8 | import Term.Pretty 9 | 10 | textTests :: TestTree 11 | textTests = 12 | testGroup "text" [ 13 | testProperty "roundTrip" propRoundTrip 14 | ] 15 | 16 | propRoundTrip :: AnyTerm 17 | -> Property 18 | propRoundTrip t = 19 | case roundTrip t of 20 | Left _ -> property False 21 | Right u -> u === t 22 | where 23 | roundTrip = 24 | fmap AnyTerm . 25 | parseTermString . 26 | prettyTermString . 27 | getAnyTerm 28 | -------------------------------------------------------------------------------- /code/old/multityped/nb-srcloc/tests/Test/Type.hs: -------------------------------------------------------------------------------- 1 | module Test.Type ( 2 | typeTests 3 | ) where 4 | 5 | import Test.Tasty 6 | 7 | import Test.Type.Text (textTests) 8 | import Test.Type.Infer (inferTests) 9 | import Test.Type.Safety (safetyTests) 10 | 11 | typeTests :: TestTree 12 | typeTests = testGroup "type" [ 13 | textTests 14 | , inferTests 15 | , safetyTests 16 | ] 17 | -------------------------------------------------------------------------------- /code/old/multityped/nb-srcloc/tests/Test/Type/Infer.hs: -------------------------------------------------------------------------------- 1 | module Test.Type.Infer ( 2 | inferTests 3 | ) where 4 | 5 | import Test.Tasty 6 | import Test.Tasty.QuickCheck 7 | 8 | import Control.Monad.Except (runExcept) 9 | 10 | import Term.Gen 11 | import Type.Infer 12 | 13 | inferTests :: TestTree 14 | inferTests = testGroup "infer" [ 15 | testProperty "wellTypedInfer" propWellTypedInfer 16 | , testProperty "illTypedInfer" propIllTypedInfer 17 | ] 18 | 19 | isRight :: Either a b -> Bool 20 | isRight (Right _) = True 21 | isRight _ = False 22 | 23 | isLeft :: Either a b -> Bool 24 | isLeft (Left _) = True 25 | isLeft _ = False 26 | 27 | propWellTypedInfer :: WellTypedTerm -> Bool 28 | propWellTypedInfer (WellTypedTerm t) = 29 | isRight . runExcept . infer $ t 30 | 31 | propIllTypedInfer :: IllTypedTerm -> Bool 32 | propIllTypedInfer (IllTypedTerm t) = 33 | isLeft . runExcept . infer $ t 34 | -------------------------------------------------------------------------------- /code/old/multityped/nb-srcloc/tests/Test/Type/Text.hs: -------------------------------------------------------------------------------- 1 | module Test.Type.Text ( 2 | textTests 3 | ) where 4 | 5 | import Test.Tasty 6 | import Test.Tasty.QuickCheck 7 | 8 | import Type.Gen 9 | import Type.Parse 10 | import Type.Pretty 11 | 12 | textTests :: TestTree 13 | textTests = 14 | testGroup "text" [ 15 | testProperty "roundTrip" propRoundTrip 16 | ] 17 | 18 | propRoundTrip :: AnyType 19 | -> Property 20 | propRoundTrip t = 21 | case roundTrip t of 22 | Left _ -> property False 23 | Right u -> u === t 24 | where 25 | roundTrip = 26 | fmap AnyType . 27 | parseTypeString . 28 | prettyTypeString . 29 | getAnyType 30 | -------------------------------------------------------------------------------- /code/old/multityped/nb/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /code/old/multityped/nb/default.nix: -------------------------------------------------------------------------------- 1 | { mkDerivation, ansi-wl-pprint, base, lens, mtl, parsers 2 | , QuickCheck, stdenv, tasty, tasty-quickcheck, trifecta 3 | , unordered-containers 4 | }: 5 | mkDerivation { 6 | pname = "nb"; 7 | version = "0.1.0.0"; 8 | src = ./.; 9 | libraryHaskellDepends = [ 10 | ansi-wl-pprint base lens mtl parsers QuickCheck trifecta 11 | unordered-containers 12 | ]; 13 | testHaskellDepends = [ base QuickCheck tasty tasty-quickcheck ]; 14 | license = stdenv.lib.licenses.bsd3; 15 | } 16 | -------------------------------------------------------------------------------- /code/old/multityped/nb/repl/Main.hs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Control.Monad.IO.Class 4 | import System.Console.Haskeline 5 | 6 | import Text.PrettyPrint.ANSI.Leijen (putDoc, (<>), line) 7 | 8 | import UI 9 | 10 | main :: IO () 11 | main = runInputT defaultSettings loop 12 | where 13 | loop :: InputT IO () 14 | loop = do 15 | i <- getInputLine "> " 16 | case i of 17 | Nothing -> return () 18 | Just "quit" -> return () 19 | Just i' -> do 20 | liftIO . putDoc . (<> line) . parseAndEval $ i' 21 | loop 22 | -------------------------------------------------------------------------------- /code/old/multityped/nb/shell.nix: -------------------------------------------------------------------------------- 1 | { nixpkgs ? import {}, compiler ? "default" }: 2 | 3 | let 4 | 5 | inherit (nixpkgs) pkgs; 6 | 7 | f = { mkDerivation, ansi-wl-pprint, base, lens, mtl, parsers 8 | , QuickCheck, stdenv, tasty, tasty-quickcheck, trifecta 9 | , unordered-containers 10 | }: 11 | mkDerivation { 12 | pname = "nb"; 13 | version = "0.1.0.0"; 14 | src = ./.; 15 | libraryHaskellDepends = [ 16 | ansi-wl-pprint base lens mtl parsers QuickCheck trifecta 17 | unordered-containers 18 | ]; 19 | testHaskellDepends = [ base QuickCheck tasty tasty-quickcheck ]; 20 | license = stdenv.lib.licenses.bsd3; 21 | }; 22 | 23 | haskellPackages = if compiler == "default" 24 | then pkgs.haskellPackages 25 | else pkgs.haskell.packages.${compiler}; 26 | 27 | drv = haskellPackages.callPackage f {}; 28 | 29 | in 30 | 31 | if pkgs.lib.inNixShell then drv.env else drv 32 | -------------------------------------------------------------------------------- /code/old/multityped/nb/src/Term.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TemplateHaskell #-} 2 | module Term where 3 | 4 | import Control.Lens.TH 5 | 6 | data Term = 7 | TmZero 8 | | TmSucc Term 9 | | TmPred Term 10 | | TmFalse 11 | | TmTrue 12 | | TmIf Term Term Term 13 | | TmIsZero Term 14 | deriving (Eq, Ord, Show) 15 | 16 | makeClassyPrisms ''Term 17 | 18 | size :: Term -> Int 19 | size TmZero = 1 20 | size (TmSucc t) = 1 + size t 21 | size (TmPred t) = 1 + size t 22 | size TmFalse = 1 23 | size TmTrue = 1 24 | size (TmIf t1 t2 t3) = 1 + size t1 + size t2 + size t3 25 | size (TmIsZero t) = 1 + size t 26 | -------------------------------------------------------------------------------- /code/old/multityped/nb/src/Term/Eval/Value.hs: -------------------------------------------------------------------------------- 1 | module Term.Eval.Value where 2 | 3 | import Control.Applicative ((<|>)) 4 | 5 | import Term 6 | 7 | bv :: Term 8 | -> Maybe Term 9 | bv TmFalse = Just TmFalse 10 | bv TmTrue = Just TmTrue 11 | bv _ = Nothing 12 | 13 | nv :: Term 14 | -> Maybe Term 15 | nv TmZero = Just TmZero 16 | nv (TmSucc t) = TmSucc <$> nv t 17 | nv _ = Nothing 18 | 19 | value :: Term 20 | -> Maybe Term 21 | value t = 22 | bv t <|> nv t 23 | -------------------------------------------------------------------------------- /code/old/multityped/nb/src/Type.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TemplateHaskell #-} 2 | module Type where 3 | 4 | import Control.Lens.TH 5 | 6 | data Type = 7 | TyBool 8 | | TyNat 9 | deriving (Eq, Ord, Show) 10 | 11 | makeClassyPrisms ''Type 12 | 13 | -------------------------------------------------------------------------------- /code/old/multityped/nb/src/Type/Error/Gen.hs: -------------------------------------------------------------------------------- 1 | module Type.Error.Gen where 2 | 3 | import Test.QuickCheck 4 | 5 | import Type 6 | import Type.Gen 7 | import Type.Error 8 | 9 | genTeUnexpected :: Type -> Gen TypeError 10 | genTeUnexpected ex = do 11 | ac <- genNotType ex 12 | return $ TeUnexpected ac ex 13 | 14 | -- should these be generating lists of gens? 15 | genTeExpectedEq :: Type -> Gen TypeError 16 | genTeExpectedEq ty = oneof [g1, g2, g3] 17 | where 18 | g1 = do 19 | tyOther <- genNotType ty 20 | return $ TeExpectedEq ty tyOther 21 | g2 = do 22 | tyOther <- genNotType ty 23 | return $ TeExpectedEq tyOther ty 24 | g3 = do 25 | ty1 <- genType 26 | ty2 <- genNotType ty1 27 | return $ TeExpectedEq ty1 ty2 28 | 29 | genTypeError :: Type -> Gen TypeError 30 | genTypeError ty = 31 | oneof . 32 | map ($ ty) $ [ 33 | genTeUnexpected 34 | , genTeExpectedEq 35 | ] 36 | -------------------------------------------------------------------------------- /code/old/multityped/nb/src/Type/Error/Pretty.hs: -------------------------------------------------------------------------------- 1 | module Type.Error.Pretty where 2 | 3 | import Text.PrettyPrint.ANSI.Leijen hiding ((<$>)) 4 | import qualified Text.PrettyPrint.ANSI.Leijen as PP 5 | 6 | import Type.Pretty 7 | import Type.Error 8 | 9 | prettyError :: TypeError 10 | -> Doc 11 | prettyError (TeUnexpected ac ex) = 12 | hang 2 (text "Unexpected type:" PP.<$> 13 | text "actual:" <+> prettyType ac PP.<$> 14 | text "expected:" <+> prettyType ex) 15 | prettyError (TeExpectedEq t1 t2) = 16 | hang 2 (text "Expected these types to be equal:" PP.<$> 17 | text "type 1:" <+> prettyType t1 PP.<$> 18 | text "type 2:" <+> prettyType t2) 19 | prettyError TeUnknownType = 20 | text "Unknown type" 21 | -------------------------------------------------------------------------------- /code/old/multityped/nb/src/Type/Gen.hs: -------------------------------------------------------------------------------- 1 | module Type.Gen where 2 | 3 | import Test.QuickCheck (Gen, Arbitrary(..), elements) 4 | 5 | import Type 6 | 7 | genType :: Gen Type 8 | genType = elements [TyBool, TyNat] 9 | 10 | genNotType :: Type -> Gen Type 11 | genNotType TyBool = return TyNat 12 | genNotType TyNat = return TyBool 13 | 14 | shrinkType :: Type -> [Type] 15 | shrinkType = const [] 16 | 17 | newtype AnyType = AnyType { getAnyType :: Type } 18 | deriving (Eq, Ord, Show) 19 | 20 | instance Arbitrary AnyType where 21 | arbitrary = AnyType <$> genType 22 | shrink = fmap AnyType . shrinkType . getAnyType 23 | -------------------------------------------------------------------------------- /code/old/multityped/nb/src/Type/Pretty.hs: -------------------------------------------------------------------------------- 1 | module Type.Pretty where 2 | 3 | import Control.Lens (preview) 4 | import Data.Foldable (asum) 5 | import Data.Maybe (fromMaybe) 6 | 7 | import Text.PrettyPrint.ANSI.Leijen 8 | 9 | import Type 10 | 11 | printTyBool :: Type -> Maybe Doc 12 | printTyBool = fmap (const . text $ "Bool") . preview _TyBool 13 | 14 | printTyNat :: Type -> Maybe Doc 15 | printTyNat = fmap (const . text $ "Nat") . preview _TyNat 16 | 17 | prettyType :: Type -> Doc 18 | prettyType t = 19 | fromMaybe empty . 20 | asum . 21 | map ($ t) $ [ 22 | printTyBool 23 | , printTyNat 24 | ] 25 | 26 | docString :: Doc -> String 27 | docString d = displayS (renderPretty 0.4 40 (plain d)) "" 28 | 29 | prettyString :: Type -> String 30 | prettyString = docString . prettyType 31 | -------------------------------------------------------------------------------- /code/old/multityped/nb/src/UI.hs: -------------------------------------------------------------------------------- 1 | module UI where 2 | 3 | import Control.Monad.Except 4 | import Text.PrettyPrint.ANSI.Leijen (Doc, (<+>), text) 5 | 6 | import Term.Parse 7 | import Term.Pretty 8 | import Term.Eval.SmallStep 9 | 10 | import Type.Pretty 11 | import Type.Error.Pretty 12 | import Type.Infer 13 | 14 | parseAndEval :: String -> Doc 15 | parseAndEval s = 16 | case parseTermString s of 17 | Left e -> e 18 | Right tm -> case (runExcept . infer) tm of 19 | Left e -> prettyError e 20 | Right ty -> printTerm (sEval tm) <+> text ":" <+> prettyType ty 21 | -------------------------------------------------------------------------------- /code/old/multityped/nb/tests/Test.hs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Test.Tasty 4 | 5 | import Test.Term (termTests) 6 | import Test.Type (typeTests) 7 | 8 | main :: IO () 9 | main = defaultMain tests 10 | 11 | tests :: TestTree 12 | tests = testGroup "Tests" [ 13 | termTests 14 | , typeTests 15 | ] 16 | 17 | -------------------------------------------------------------------------------- /code/old/multityped/nb/tests/Test/Term.hs: -------------------------------------------------------------------------------- 1 | module Test.Term where 2 | 3 | import Test.Tasty 4 | 5 | import Test.Term.Text (textTests) 6 | import Test.Term.Eval (evalTests) 7 | 8 | termTests :: TestTree 9 | termTests = testGroup "term" [ 10 | textTests 11 | , evalTests 12 | ] 13 | -------------------------------------------------------------------------------- /code/old/multityped/nb/tests/Test/Term/Text.hs: -------------------------------------------------------------------------------- 1 | module Test.Term.Text where 2 | 3 | import Test.Tasty 4 | import Test.Tasty.QuickCheck 5 | 6 | import Term.Gen 7 | import Term.Parse 8 | import Term.Pretty 9 | 10 | textTests :: TestTree 11 | textTests = 12 | testGroup "text" [ 13 | testProperty "roundTrip" propRoundTrip 14 | ] 15 | 16 | propRoundTrip :: AnyTerm 17 | -> Property 18 | propRoundTrip (AnyTerm t) = 19 | case roundTrip t of 20 | Left _ -> property False 21 | Right u -> u === t 22 | where 23 | roundTrip = 24 | parseTermString . 25 | prettyString 26 | -------------------------------------------------------------------------------- /code/old/multityped/nb/tests/Test/Type.hs: -------------------------------------------------------------------------------- 1 | module Test.Type ( 2 | typeTests 3 | ) where 4 | 5 | import Test.Tasty 6 | 7 | import Test.Type.Text (textTests) 8 | import Test.Type.Infer (inferTests) 9 | import Test.Type.Safety (safetyTests) 10 | 11 | typeTests :: TestTree 12 | typeTests = testGroup "type" [ 13 | textTests 14 | , inferTests 15 | , safetyTests 16 | ] 17 | -------------------------------------------------------------------------------- /code/old/multityped/nb/tests/Test/Type/Infer.hs: -------------------------------------------------------------------------------- 1 | module Test.Type.Infer ( 2 | inferTests 3 | ) where 4 | 5 | import Test.Tasty 6 | import Test.Tasty.QuickCheck 7 | 8 | import Control.Monad.Except (runExcept) 9 | 10 | import Term.Gen 11 | import Type.Infer 12 | 13 | inferTests :: TestTree 14 | inferTests = testGroup "infer" [ 15 | testProperty "wellTypedInfer" propWellTypedInfer 16 | , testProperty "illTypedInfer" propIllTypedInfer 17 | ] 18 | 19 | isRight :: Either a b -> Bool 20 | isRight (Right _) = True 21 | isRight _ = False 22 | 23 | isLeft :: Either a b -> Bool 24 | isLeft (Left _) = True 25 | isLeft _ = False 26 | 27 | propWellTypedInfer :: WellTypedTerm -> Bool 28 | propWellTypedInfer (WellTypedTerm t) = 29 | isRight . runExcept . infer $ t 30 | 31 | propIllTypedInfer :: IllTypedTerm -> Bool 32 | propIllTypedInfer (IllTypedTerm t) = 33 | isLeft . runExcept . infer $ t 34 | -------------------------------------------------------------------------------- /code/old/multityped/nb/tests/Test/Type/Text.hs: -------------------------------------------------------------------------------- 1 | module Test.Type.Text ( 2 | textTests 3 | ) where 4 | 5 | import Test.Tasty 6 | import Test.Tasty.QuickCheck 7 | 8 | import Type.Gen 9 | import Type.Parse 10 | import Type.Pretty 11 | 12 | textTests :: TestTree 13 | textTests = 14 | testGroup "text" [ 15 | testProperty "roundTrip" propRoundTrip 16 | ] 17 | 18 | propRoundTrip :: AnyType 19 | -> Property 20 | propRoundTrip (AnyType t) = 21 | case roundTrip t of 22 | Left _ -> property False 23 | Right u -> u === t 24 | where 25 | roundTrip = 26 | parseTypeString . 27 | prettyString 28 | -------------------------------------------------------------------------------- /code/old/multityped/old-stlc-b/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /code/old/multityped/old-stlc-b/default.nix: -------------------------------------------------------------------------------- 1 | { mkDerivation, ansi-wl-pprint, base, bound, containers, lens, mtl 2 | , parsers, prelude-extras, QuickCheck, stdenv, tasty 3 | , tasty-quickcheck, trifecta, unordered-containers 4 | }: 5 | mkDerivation { 6 | pname = "stlc-b"; 7 | version = "0.1.0.0"; 8 | src = ./.; 9 | libraryHaskellDepends = [ 10 | ansi-wl-pprint base bound containers lens mtl parsers 11 | prelude-extras QuickCheck trifecta unordered-containers 12 | ]; 13 | testHaskellDepends = [ 14 | base mtl QuickCheck tasty tasty-quickcheck trifecta 15 | ]; 16 | license = stdenv.lib.licenses.bsd3; 17 | } 18 | -------------------------------------------------------------------------------- /code/old/multityped/old-stlc-b/shell.nix: -------------------------------------------------------------------------------- 1 | { nixpkgs ? import {}, compiler ? "default" }: 2 | 3 | let 4 | 5 | inherit (nixpkgs) pkgs; 6 | 7 | f = { mkDerivation, ansi-wl-pprint, base, bound, containers, lens 8 | , mtl, parsers, prelude-extras, QuickCheck, stdenv, tasty 9 | , tasty-quickcheck, trifecta, unordered-containers 10 | }: 11 | mkDerivation { 12 | pname = "stlc-b"; 13 | version = "0.1.0.0"; 14 | src = ./.; 15 | libraryHaskellDepends = [ 16 | ansi-wl-pprint base bound containers lens mtl parsers 17 | prelude-extras QuickCheck trifecta unordered-containers 18 | ]; 19 | testHaskellDepends = [ 20 | base mtl QuickCheck tasty tasty-quickcheck trifecta 21 | ]; 22 | license = stdenv.lib.licenses.bsd3; 23 | }; 24 | 25 | haskellPackages = if compiler == "default" 26 | then pkgs.haskellPackages 27 | else pkgs.haskell.packages.${compiler}; 28 | 29 | drv = haskellPackages.callPackage f {}; 30 | 31 | in 32 | 33 | if pkgs.lib.inNixShell then drv.env else drv 34 | -------------------------------------------------------------------------------- /code/old/multityped/old-stlc-b/src/Term/Eval/Value.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE FlexibleContexts #-} 2 | module Term.Eval.Value where 3 | 4 | import Control.Applicative ((<|>)) 5 | import Control.Lens (preview) 6 | 7 | import Term 8 | 9 | bv :: (AsTermF f l n g a, TermLike f (g a)) 10 | => f -> Maybe f 11 | bv t = 12 | (t <$ preview _TmFalse t) <|> 13 | (t <$ preview _TmTrue t) 14 | 15 | lv :: (AsTermF f l n g a, TermLike f (g a)) 16 | => f -> Maybe f 17 | lv t = 18 | (t <$ preview _TmLam t) 19 | 20 | value :: (AsTermF f l n g a, TermLike f (g a)) 21 | => f 22 | -> Maybe f 23 | value t = bv t <|> lv t 24 | -------------------------------------------------------------------------------- /code/old/multityped/old-stlc-b/src/Type.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TemplateHaskell #-} 2 | {-# LANGUAGE MultiParamTypeClasses #-} 3 | {-# LANGUAGE FunctionalDependencies #-} 4 | {-# LANGUAGE FlexibleInstances #-} 5 | {-# LANGUAGE TypeFamilies #-} 6 | module Type where 7 | 8 | import Control.Lens.TH 9 | import Control.Lens.Wrapped 10 | 11 | data TypeF l f = 12 | TyBool 13 | | TyArr f f 14 | deriving (Eq, Ord, Show) 15 | 16 | makeClassyPrisms ''TypeF 17 | 18 | data Type l = Type { getType :: TypeF l (Type l) } 19 | deriving (Eq, Ord, Show) 20 | 21 | makeWrapped ''Type 22 | 23 | instance AsTypeF (Type l) l (Type l) where 24 | _TyBool = _Wrapped . _TyBool 25 | _TyArr = _Wrapped . _TyArr 26 | 27 | -------------------------------------------------------------------------------- /code/old/multityped/stlc-b/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /code/old/multityped/stlc-b/default.nix: -------------------------------------------------------------------------------- 1 | { mkDerivation, ansi-wl-pprint, base, bifunctors, bound, containers 2 | , haskeline, lens, mtl, parsers, prelude-extras, QuickCheck, stdenv 3 | , tasty, tasty-quickcheck, transformers, trifecta 4 | , unordered-containers 5 | }: 6 | mkDerivation { 7 | pname = "stlc-b"; 8 | version = "0.1.0.0"; 9 | src = ./.; 10 | isLibrary = true; 11 | isExecutable = true; 12 | libraryHaskellDepends = [ 13 | ansi-wl-pprint base bifunctors bound containers lens mtl parsers 14 | prelude-extras QuickCheck trifecta unordered-containers 15 | ]; 16 | executableHaskellDepends = [ 17 | ansi-wl-pprint base haskeline transformers 18 | ]; 19 | testHaskellDepends = [ 20 | base mtl QuickCheck tasty tasty-quickcheck trifecta 21 | ]; 22 | license = stdenv.lib.licenses.bsd3; 23 | } 24 | -------------------------------------------------------------------------------- /code/old/multityped/stlc-b/repl/Main.hs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Control.Monad.IO.Class 4 | import System.Console.Haskeline 5 | 6 | import Text.PrettyPrint.ANSI.Leijen (putDoc, (<>), line) 7 | 8 | import UI 9 | 10 | main :: IO () 11 | main = runInputT defaultSettings loop 12 | where 13 | loop :: InputT IO () 14 | loop = do 15 | i <- getInputLine "> " 16 | case i of 17 | Nothing -> return () 18 | Just "quit" -> return () 19 | Just i' -> do 20 | liftIO . putDoc . (<> line) . parseAndEval $ i' 21 | loop 22 | -------------------------------------------------------------------------------- /code/old/multityped/stlc-b/src/Loc.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TypeFamilies #-} 2 | {-# LANGUAGE RankNTypes #-} 3 | module Loc where 4 | 5 | import Control.Lens (preview, review) 6 | import Control.Lens.Iso (Iso', iso) 7 | import Control.Lens.Prism (Prism', aside) 8 | 9 | class WithLoc f where 10 | type Loc f 11 | type Without f 12 | 13 | _Loc :: Prism' f (Loc f, f) 14 | 15 | stripLoc :: f -> Without f 16 | 17 | _WithLoc :: Iso' f (Maybe (Loc f), f) 18 | _WithLoc = iso there back 19 | where 20 | there t = case preview _Loc t of 21 | Just (l, t') -> (Just l, t') 22 | Nothing -> (Nothing, t) 23 | back (Nothing, t) = t 24 | back (Just l, t) = review _Loc (l, t) 25 | 26 | withLoc :: WithLoc f 27 | => Prism' f a 28 | -> f 29 | -> Maybe (Maybe (Loc f), a) 30 | withLoc p = preview (_WithLoc . aside p) 31 | -------------------------------------------------------------------------------- /code/old/multityped/stlc-b/src/Term/Eval/Value.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE FlexibleContexts #-} 2 | module Term.Eval.Value where 3 | 4 | import Control.Applicative ((<|>)) 5 | 6 | import Term 7 | 8 | bv :: Term n l a 9 | -> Maybe (Term n l a) 10 | bv TmFalse = Just TmFalse 11 | bv TmTrue = Just TmTrue 12 | bv _ = Nothing 13 | 14 | lv :: Term n l a 15 | -> Maybe (Term n l a) 16 | lv l@TmLam{} = Just l 17 | lv _ = Nothing 18 | 19 | value :: Term n l a 20 | -> Maybe (Term n l a) 21 | value t = 22 | bv t <|> lv t 23 | -------------------------------------------------------------------------------- /code/old/multityped/stlc-b/src/Type.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TemplateHaskell #-} 2 | {-# LANGUAGE MultiParamTypeClasses #-} 3 | {-# LANGUAGE FunctionalDependencies #-} 4 | {-# LANGUAGE FlexibleInstances #-} 5 | {-# LANGUAGE TypeFamilies #-} 6 | module Type where 7 | 8 | import Control.Lens.TH 9 | 10 | import Loc 11 | 12 | data Type l = 13 | TyBool 14 | | TyArr (Type l) (Type l) 15 | | TyLoc l (Type l) 16 | deriving (Eq, Ord, Show) 17 | 18 | makeClassyPrisms ''Type 19 | 20 | instance WithLoc (Type l) where 21 | type Loc (Type l) = l 22 | type Without (Type l) = Type () 23 | 24 | _Loc = _TyLoc 25 | 26 | stripLoc TyBool = TyBool 27 | stripLoc (TyArr t1 t2) = TyArr (stripLoc t1) (stripLoc t2) 28 | stripLoc (TyLoc _ t) = stripLoc t 29 | -------------------------------------------------------------------------------- /code/old/multityped/stlc-b/src/UI.hs: -------------------------------------------------------------------------------- 1 | module UI where 2 | 3 | import Control.Monad.Except 4 | import Text.PrettyPrint.ANSI.Leijen (Doc, (<+>), text) 5 | 6 | import Term.Parse 7 | import Term.Pretty 8 | import Term.Eval.SmallStep 9 | 10 | import Type.Pretty 11 | import Type.Error.Message 12 | import Type.Infer 13 | 14 | parseAndEval :: String -> Doc 15 | parseAndEval s = 16 | case parseTermString s of 17 | Left e -> e 18 | Right tm -> case (runExcept . infer) tm of 19 | Left e -> prettyError e 20 | Right ty -> printTerm (sEval tm) <+> text ":" <+> prettyType ty 21 | -------------------------------------------------------------------------------- /code/old/multityped/stlc-b/tests/Test.hs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Test.Tasty 4 | 5 | import Test.Term (termTests) 6 | import Test.Type (typeTests) 7 | 8 | main :: IO () 9 | main = defaultMain tests 10 | 11 | tests :: TestTree 12 | tests = testGroup "Tests" [ 13 | termTests 14 | , typeTests 15 | ] 16 | -------------------------------------------------------------------------------- /code/old/multityped/stlc-b/tests/Test/Term.hs: -------------------------------------------------------------------------------- 1 | module Test.Term where 2 | 3 | import Test.Tasty 4 | 5 | import Test.Term.Text (textTests) 6 | import Test.Term.Eval (evalTests) 7 | 8 | termTests :: TestTree 9 | termTests = testGroup "term" [ 10 | textTests 11 | , evalTests 12 | ] 13 | -------------------------------------------------------------------------------- /code/old/multityped/stlc-b/tests/Test/Term/Text.hs: -------------------------------------------------------------------------------- 1 | module Test.Term.Text where 2 | 3 | import Test.Tasty 4 | import Test.Tasty.QuickCheck 5 | 6 | import Term.Gen 7 | import Term.Parse 8 | import Term.Pretty 9 | 10 | textTests :: TestTree 11 | textTests = 12 | testGroup "text" [ 13 | testProperty "roundTrip" propRoundTrip 14 | ] 15 | 16 | propRoundTrip :: AnyTerm 17 | -> Property 18 | propRoundTrip t = 19 | case roundTrip t of 20 | Left _ -> property False 21 | Right u -> u === t 22 | where 23 | roundTrip = 24 | fmap AnyTerm . 25 | parseTermString . 26 | prettyTermString . 27 | getAnyTerm 28 | -------------------------------------------------------------------------------- /code/old/multityped/stlc-b/tests/Test/Type.hs: -------------------------------------------------------------------------------- 1 | module Test.Type ( 2 | typeTests 3 | ) where 4 | 5 | import Test.Tasty 6 | 7 | import Test.Type.Text (textTests) 8 | import Test.Type.Infer (inferTests) 9 | import Test.Type.Safety (safetyTests) 10 | 11 | typeTests :: TestTree 12 | typeTests = testGroup "type" [ 13 | textTests 14 | , inferTests 15 | , safetyTests 16 | ] 17 | -------------------------------------------------------------------------------- /code/old/multityped/stlc-b/tests/Test/Type/Infer.hs: -------------------------------------------------------------------------------- 1 | module Test.Type.Infer ( 2 | inferTests 3 | ) where 4 | 5 | import Test.Tasty 6 | import Test.Tasty.QuickCheck 7 | 8 | import Control.Monad.Except (runExcept) 9 | 10 | import Term.Gen 11 | import Type.Infer 12 | 13 | inferTests :: TestTree 14 | inferTests = testGroup "infer" [ 15 | testProperty "wellTypedInfer" propWellTypedInfer 16 | , testProperty "illTypedInfer" propIllTypedInfer 17 | ] 18 | 19 | isRight :: Either a b -> Bool 20 | isRight (Right _) = True 21 | isRight _ = False 22 | 23 | isLeft :: Either a b -> Bool 24 | isLeft (Left _) = True 25 | isLeft _ = False 26 | 27 | propWellTypedInfer :: WellTypedTerm -> Bool 28 | propWellTypedInfer (WellTypedTerm t) = 29 | isRight . runExcept . infer $ t 30 | 31 | propIllTypedInfer :: IllTypedTerm -> Bool 32 | propIllTypedInfer (IllTypedTerm t) = 33 | isLeft . runExcept . infer $ t 34 | -------------------------------------------------------------------------------- /code/old/multityped/stlc-b/tests/Test/Type/Text.hs: -------------------------------------------------------------------------------- 1 | module Test.Type.Text ( 2 | textTests 3 | ) where 4 | 5 | import Test.Tasty 6 | import Test.Tasty.QuickCheck 7 | 8 | import Type.Gen 9 | import Type.Parse 10 | import Type.Pretty 11 | 12 | textTests :: TestTree 13 | textTests = 14 | testGroup "text" [ 15 | testProperty "roundTrip" propRoundTrip 16 | ] 17 | 18 | propRoundTrip :: AnyType 19 | -> Property 20 | propRoundTrip t = 21 | case roundTrip t of 22 | Left _ -> property False 23 | Right u -> u === t 24 | where 25 | roundTrip = 26 | fmap AnyType . 27 | parseTypeString . 28 | prettyTypeString . 29 | getAnyType 30 | -------------------------------------------------------------------------------- /code/old/prototypes/arith/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /code/old/prototypes/arith/arith.cabal: -------------------------------------------------------------------------------- 1 | -- Initial arith.cabal generated by cabal init. For further documentation, 2 | -- see http://haskell.org/cabal/users-guide/ 3 | 4 | name: arith 5 | version: 0.1.0.0 6 | -- synopsis: 7 | -- description: 8 | license: BSD3 9 | license-file: LICENSE 10 | author: Dave Laing 11 | maintainer: dave.laing.80@gmail.com 12 | -- copyright: 13 | -- category: 14 | build-type: Simple 15 | -- extra-source-files: 16 | cabal-version: >=1.10 17 | 18 | library 19 | exposed-modules: Rules, STLC, STLC.Eval, STLC.Check, STLC.Type, STLC.Tag, STLC.Classy 20 | -- other-modules: 21 | other-extensions: TemplateHaskell 22 | build-depends: base >=4.8 && <4.9, lens >=4.13 && <4.14, QuickCheck, bound, prelude-extras, mtl, profunctors, semigroups, semigroupoids, validation, tagged, singletons 23 | hs-source-dirs: src 24 | default-language: Haskell2010 25 | -------------------------------------------------------------------------------- /code/old/prototypes/arith/default.nix: -------------------------------------------------------------------------------- 1 | { mkDerivation, base, bound, lens, mtl, prelude-extras, profunctors 2 | , QuickCheck, semigroupoids, semigroups, singletons, stdenv, tagged 3 | , validation 4 | }: 5 | mkDerivation { 6 | pname = "arith"; 7 | version = "0.1.0.0"; 8 | src = ./.; 9 | libraryHaskellDepends = [ 10 | base bound lens mtl prelude-extras profunctors QuickCheck 11 | semigroupoids semigroups singletons tagged validation 12 | ]; 13 | license = stdenv.lib.licenses.bsd3; 14 | } 15 | -------------------------------------------------------------------------------- /code/old/prototypes/arith/shell.nix: -------------------------------------------------------------------------------- 1 | with (import {}).pkgs; 2 | let modifiedHaskellPackages = haskellPackages.override { 3 | overrides = self: super: { 4 | arith = self.callPackage ./. {}; 5 | }; 6 | }; 7 | in modifiedHaskellPackages.arith.env 8 | -------------------------------------------------------------------------------- /code/old/prototypes/arith/src/STLC/Type.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TemplateHaskell #-} 2 | {-# LANGUAGE DataKinds #-} 3 | {-# LANGUAGE PolyKinds #-} 4 | {-# LANGUAGE ScopedTypeVariables #-} 5 | {-# LANGUAGE KindSignatures #-} 6 | {-# LANGUAGE TypeFamilies #-} 7 | {-# LANGUAGE UndecidableInstances #-} 8 | {-# LANGUAGE GADTs #-} 9 | {-# LANGUAGE InstanceSigs #-} 10 | {-# LANGUAGE MultiParamTypeClasses #-} 11 | {-# LANGUAGE FlexibleInstances #-} 12 | module STLC.Type where 13 | 14 | import Data.Singletons.Prelude 15 | import Data.Singletons.TH 16 | 17 | singletons [d| 18 | data Type = 19 | TyInt 20 | | TyBool 21 | | TyArr Type Type 22 | deriving (Eq, Ord, Show) 23 | |] 24 | -------------------------------------------------------------------------------- /code/old/prototypes/bits/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /code/old/prototypes/bits/bits.cabal: -------------------------------------------------------------------------------- 1 | -- Initial bits.cabal generated by cabal init. For further documentation, 2 | -- see http://haskell.org/cabal/users-guide/ 3 | 4 | name: bits 5 | version: 0.1.0.0 6 | -- synopsis: 7 | -- description: 8 | license: BSD3 9 | license-file: LICENSE 10 | author: Dave Laing 11 | maintainer: dave.laing.80@gmail.com 12 | -- copyright: 13 | category: Language 14 | build-type: Simple 15 | -- extra-source-files: 16 | cabal-version: >=1.10 17 | 18 | library 19 | exposed-modules: Bits, Coproduct 20 | -- other-modules: 21 | -- other-extensions: 22 | build-depends: base >=4.8 && <4.9, bound >=1.0 && <1.1, prelude-extras >= 0.4 && < 0.5 23 | hs-source-dirs: src 24 | default-language: Haskell2010 25 | -------------------------------------------------------------------------------- /code/old/prototypes/bits/default.nix: -------------------------------------------------------------------------------- 1 | { mkDerivation, base, bound, prelude-extras, stdenv }: 2 | mkDerivation { 3 | pname = "bits"; 4 | version = "0.1.0.0"; 5 | src = ./.; 6 | libraryHaskellDepends = [ base bound prelude-extras ]; 7 | license = stdenv.lib.licenses.bsd3; 8 | } 9 | -------------------------------------------------------------------------------- /code/old/prototypes/bits/shell.nix: -------------------------------------------------------------------------------- 1 | with (import {}).pkgs; 2 | let modifiedHaskellPackages = haskellPackages.override { 3 | overrides = self: super: { 4 | bits = self.callPackage ./. {}; 5 | }; 6 | }; 7 | in modifiedHaskellPackages.bits.env 8 | -------------------------------------------------------------------------------- /code/old/prototypes/classy/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /code/old/prototypes/classy/default.nix: -------------------------------------------------------------------------------- 1 | { mkDerivation, base, bifunctors, bound, errors, lens, profunctors 2 | , QuickCheck, semigroupoids, semigroups, singletons, stdenv, tagged 3 | }: 4 | mkDerivation { 5 | pname = "classy"; 6 | version = "0.1.0.0"; 7 | src = ./.; 8 | libraryHaskellDepends = [ 9 | base bifunctors bound errors lens profunctors QuickCheck 10 | semigroupoids semigroups singletons tagged 11 | ]; 12 | license = stdenv.lib.licenses.bsd3; 13 | } 14 | -------------------------------------------------------------------------------- /code/old/prototypes/classy/shell.nix: -------------------------------------------------------------------------------- 1 | with (import {}).pkgs; 2 | let modifiedHaskellPackages = haskellPackages.override { 3 | overrides = self: super: { 4 | classy = self.callPackage ./. {}; 5 | }; 6 | }; 7 | in modifiedHaskellPackages.classy.env 8 | -------------------------------------------------------------------------------- /code/old/prototypes/classy/src/STLC/Syntax/Bool.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DataKinds #-} 2 | {-# LANGUAGE FlexibleContexts #-} 3 | module STLC.Syntax.Bool where 4 | 5 | import Data.Tagged 6 | 7 | import Term.Component.Bool 8 | 9 | import STLC.Type 10 | 11 | bool :: WithTmBool Type f a => Bool -> Tagged TyBool (f a) 12 | bool = Tagged . Term.Component.Bool.bool 13 | 14 | 15 | -------------------------------------------------------------------------------- /code/old/prototypes/classy/src/STLC/Syntax/Eq.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DataKinds #-} 2 | {-# LANGUAGE FlexibleContexts #-} 3 | module STLC.Syntax.Eq where 4 | 5 | import Data.Tagged 6 | 7 | import Term.Component.Eq 8 | 9 | import STLC.Type 10 | 11 | infix 4 .==. 12 | (.==.) :: WithTmEq Type f a => Tagged TyInt (f a) -> Tagged TyInt (f a) -> Tagged TyBool (f a) 13 | (.==.) x y = retag ((Term.Component.Eq..==.) <$> x <*> y) 14 | 15 | infix 4 ./=. 16 | (./=.) :: WithTmEq Type f a => Tagged TyInt (f a) -> Tagged TyInt (f a) -> Tagged TyBool (f a) 17 | (./=.) x y = retag ((Term.Component.Eq../=.) <$> x <*> y) 18 | 19 | -------------------------------------------------------------------------------- /code/old/prototypes/classy/src/STLC/Syntax/Int.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DataKinds #-} 2 | {-# LANGUAGE FlexibleContexts #-} 3 | module STLC.Syntax.Int where 4 | 5 | import Data.Tagged 6 | 7 | import Term.Component.Int 8 | 9 | import STLC.Type 10 | 11 | int :: WithTmInt Type f a => Int -> Tagged TyInt (f a) 12 | int = Tagged . Term.Component.Int.int 13 | 14 | -------------------------------------------------------------------------------- /code/old/prototypes/classy/src/STLC/Syntax/LC.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DataKinds #-} 2 | {-# LANGUAGE FlexibleContexts #-} 3 | module STLC.Syntax.LC where 4 | 5 | import Data.Tagged 6 | import Data.Singletons (fromSing) 7 | 8 | import Term.Component.LC 9 | 10 | import STLC.Type 11 | 12 | v :: WithTmLc n Type f a => a -> Tagged t (f n Type a) 13 | v = Tagged . Term.Component.LC.v 14 | 15 | infixr 0 .!. 16 | (.!.) :: (WithTmLc n Type f n, Monad (f n Type), Eq n) => SType x -> n -> Tagged y (f n Type n) -> Tagged (TyArrow x y) (f n Type n) 17 | (.!.) t n e= Tagged $ lam (fromSing t) n (untag e) 18 | 19 | infixl 9 .@. 20 | (.@.) :: (WithTmLc n Type f a) => Tagged (TyArrow x y ) (f n Type a) -> Tagged x (f n Type a) -> Tagged y (f n Type a) 21 | (.@.) f x = Tagged ((Term.Component.LC..@.) (untag f) (untag x)) 22 | 23 | -------------------------------------------------------------------------------- /code/old/prototypes/classy/src/STLC/Syntax/Logic.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DataKinds #-} 2 | {-# LANGUAGE FlexibleContexts #-} 3 | module STLC.Syntax.Logic where 4 | 5 | import Data.Tagged 6 | 7 | import Term.Component.Logic 8 | 9 | import STLC.Type 10 | 11 | infixr 3 .&&. 12 | (.&&.) :: WithTmLogic Type f a => Tagged TyBool (f a) -> Tagged TyBool (f a) -> Tagged TyBool (f a) 13 | (.&&.) x y = (Term.Component.Logic..&&.) <$> x <*> y 14 | 15 | infixr 2 .||. 16 | (.||.) :: WithTmLogic Type f a => Tagged TyBool (f a) -> Tagged TyBool (f a) -> Tagged TyBool (f a) 17 | (.||.) x y = (Term.Component.Logic..||.) <$> x <*> y 18 | 19 | not :: WithTmLogic Type f a => Tagged TyBool (f a) -> Tagged TyBool (f a) 20 | not x = Term.Component.Logic.not <$> x 21 | 22 | 23 | -------------------------------------------------------------------------------- /code/old/prototypes/classy/src/STLC/Syntax/Num.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DataKinds #-} 2 | {-# LANGUAGE FlexibleContexts #-} 3 | module STLC.Syntax.Num where 4 | 5 | import Data.Tagged 6 | 7 | import Term.Component.Num 8 | 9 | import STLC.Type 10 | 11 | infixl 6 .+. 12 | (.+.) :: WithTmNum Type f a => Tagged TyInt (f a) -> Tagged TyInt (f a) -> Tagged TyInt (f a) 13 | (.+.) x y = (Term.Component.Num..+.) <$> x <*> y 14 | 15 | infixl 6 .-. 16 | (.-.) :: WithTmNum Type f a => Tagged TyInt (f a) -> Tagged TyInt (f a) -> Tagged TyInt (f a) 17 | (.-.) x y = (Term.Component.Num..-.) <$> x <*> y 18 | 19 | infixl 7 .*. 20 | (.*.) :: WithTmNum Type f a => Tagged TyInt (f a) -> Tagged TyInt (f a) -> Tagged TyInt (f a) 21 | (.*.) x y = (Term.Component.Num..*.) <$> x <*> y 22 | 23 | neg :: WithTmNum Type f a => Tagged TyInt (f a) -> Tagged TyInt (f a) 24 | neg x = Term.Component.Num.neg <$> x 25 | 26 | -------------------------------------------------------------------------------- /code/old/prototypes/classy/src/STLC/Syntax/Ord.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DataKinds #-} 2 | {-# LANGUAGE FlexibleContexts #-} 3 | module STLC.Syntax.Ord where 4 | 5 | import Data.Tagged 6 | 7 | import Term.Component.Ord 8 | 9 | import STLC.Type 10 | 11 | infix 4 .<. 12 | (.<.) :: WithTmOrd Type f a => Tagged TyInt (f a) -> Tagged TyInt (f a) -> Tagged TyBool (f a) 13 | (.<.) x y = retag ((Term.Component.Ord..<.) <$> x <*> y) 14 | 15 | infix 4 .<=. 16 | (.<=.) :: WithTmOrd Type f a => Tagged TyInt (f a) -> Tagged TyInt (f a) -> Tagged TyBool (f a) 17 | (.<=.) x y = retag ((Term.Component.Ord..<=.) <$> x <*> y) 18 | 19 | infix 4 .>. 20 | (.>.) :: WithTmOrd Type f a => Tagged TyInt (f a) -> Tagged TyInt (f a) -> Tagged TyBool (f a) 21 | (.>.) x y = retag ((Term.Component.Ord..>.) <$> x <*> y) 22 | 23 | infix 4 .>=. 24 | (.>=.) :: WithTmOrd Type f a => Tagged TyInt (f a) -> Tagged TyInt (f a) -> Tagged TyBool (f a) 25 | (.>=.) x y = retag ((Term.Component.Ord..>=.) <$> x <*> y) 26 | 27 | -------------------------------------------------------------------------------- /code/old/prototypes/classy/src/Term/Component/Bool.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TemplateHaskell #-} 2 | {-# LANGUAGE ConstraintKinds #-} 3 | {-# LANGUAGE TypeFamilies #-} 4 | {-# LANGUAGE FlexibleInstances #-} 5 | {-# LANGUAGE MultiParamTypeClasses #-} 6 | {-# LANGUAGE FunctionalDependencies #-} 7 | {-# LANGUAGE KindSignatures #-} 8 | {-# LANGUAGE PolyKinds #-} 9 | module Term.Component.Bool where 10 | 11 | import Control.Lens 12 | 13 | import Type.Component.Bool 14 | 15 | import Term.Value 16 | 17 | data TmBool (t :: k0) (f :: k1 -> *) (a :: k1) = TmBoolLit Bool 18 | deriving (Eq, Ord, Show) 19 | 20 | makeClassyPrisms ''TmBool 21 | 22 | type WithTmBool t f a = (AsTyBool t, AsTmBool (f a) t f a) 23 | 24 | instance IsValue (TmBool t f a) where 25 | isValue = const True 26 | 27 | -- Type checking and inference 28 | 29 | -- Small step semantics 30 | 31 | -- Big step semantics 32 | 33 | -- Syntax 34 | 35 | bool :: WithTmBool t f a => Bool -> f a 36 | bool = review _TmBoolLit 37 | 38 | -------------------------------------------------------------------------------- /code/old/prototypes/classy/src/Term/Component/Int.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TemplateHaskell #-} 2 | {-# LANGUAGE ConstraintKinds #-} 3 | {-# LANGUAGE TypeFamilies #-} 4 | {-# LANGUAGE FlexibleInstances #-} 5 | {-# LANGUAGE MultiParamTypeClasses #-} 6 | {-# LANGUAGE FunctionalDependencies #-} 7 | {-# LANGUAGE KindSignatures #-} 8 | {-# LANGUAGE PolyKinds #-} 9 | module Term.Component.Int where 10 | 11 | import Control.Lens 12 | 13 | import Type.Component.Int 14 | 15 | import Term.Value 16 | 17 | data TmInt (t :: k0) (f :: k1 -> *) (a :: k1) = TmIntLit Int 18 | deriving (Eq, Ord, Show) 19 | 20 | makeClassyPrisms ''TmInt 21 | 22 | type WithTmInt t f a = (AsTyInt t, AsTmInt (f a) t f a) 23 | 24 | instance IsValue (TmInt t f a) where 25 | isValue = const True 26 | 27 | -- Patterns 28 | 29 | pIntLit :: WithTmInt t f a => f a -> Maybe Int 30 | pIntLit = preview _TmIntLit 31 | 32 | -- Type checking and inference 33 | 34 | -- Small step semantics 35 | 36 | -- Big step semantics 37 | 38 | -- Syntax 39 | 40 | int :: WithTmInt t f a => Int -> f a 41 | int = review _TmIntLit 42 | 43 | -------------------------------------------------------------------------------- /code/old/prototypes/classy/src/Term/Eval.hs: -------------------------------------------------------------------------------- 1 | module Term.Eval where 2 | -------------------------------------------------------------------------------- /code/old/prototypes/classy/src/Term/Value.hs: -------------------------------------------------------------------------------- 1 | module Term.Value where 2 | 3 | class IsValue t where 4 | isValue :: t -> Bool 5 | -------------------------------------------------------------------------------- /code/old/prototypes/classy/src/Type/Check.hs: -------------------------------------------------------------------------------- 1 | module Type.Check where 2 | -------------------------------------------------------------------------------- /code/old/prototypes/classy/src/Type/Component/Arrow.hs: -------------------------------------------------------------------------------- 1 | module Type.Component.Arrow where 2 | 3 | import Control.Lens 4 | 5 | class AsTyArrow t where 6 | _TyArrow :: Prism' t (t, t) 7 | -------------------------------------------------------------------------------- /code/old/prototypes/classy/src/Type/Component/Bool.hs: -------------------------------------------------------------------------------- 1 | module Type.Component.Bool where 2 | 3 | import Control.Lens 4 | 5 | class AsTyBool t where 6 | _TyBool :: Prism' t () 7 | -------------------------------------------------------------------------------- /code/old/prototypes/classy/src/Type/Component/Int.hs: -------------------------------------------------------------------------------- 1 | module Type.Component.Int where 2 | 3 | import Control.Lens 4 | 5 | class AsTyInt t where 6 | _TyInt :: Prism' t () 7 | -------------------------------------------------------------------------------- /code/old/prototypes/data-decl/src/Check.hs: -------------------------------------------------------------------------------- 1 | module Check ( 2 | ) where 3 | 4 | import Term 5 | import Type 6 | 7 | data TypeError = T 8 | 9 | data Ops = 10 | OEqI | OAdd | OMul 11 | 12 | opType :: Ops -> Type 13 | opType OEqI = Arrow TypeInt (Arrow TypeInt TypeBool) 14 | opType OEqI = Arrow TypeInt (Arrow TypeInt TypeBool) 15 | opType OEqI = Arrow TypeInt (Arrow TypeInt TypeBool) 16 | 17 | -- error monad, or validation? 18 | typeCheck :: Term n a -> Either TypeError Type 19 | typeCheck (LitI _ ) = return TypeInt 20 | typeCheck (LitB _ ) = return TypeBool 21 | typeCheck (LitS _ ) = return TypeString 22 | typeCheck (Add x y) = do 23 | x' <- typeCheck x 24 | y' <- typeCheck y 25 | if (x == TypeInt) && (y == TypeInt) 26 | then return TypeInt 27 | else _ 28 | 29 | -- TODO infer free var type 30 | -- bound should be tagged at the binding site, however we can probably 31 | -- infer that too 32 | -------------------------------------------------------------------------------- /code/old/prototypes/data-decl/src/Type.hs: -------------------------------------------------------------------------------- 1 | module Type where 2 | 3 | data Type = 4 | TInt 5 | | TBool 6 | | TString 7 | | Arrow Type Type 8 | deriving (Eq, Ord, Show) 9 | -------------------------------------------------------------------------------- /code/old/prototypes/frag/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /code/old/prototypes/frag/default.nix: -------------------------------------------------------------------------------- 1 | { mkDerivation, ansi-wl-pprint, base, bound, containers, mtl 2 | , parsers, prelude-extras, QuickCheck, stdenv, trifecta 3 | , unordered-containers 4 | }: 5 | mkDerivation { 6 | pname = "frag"; 7 | version = "0.1.0.0"; 8 | src = ./.; 9 | libraryHaskellDepends = [ 10 | ansi-wl-pprint base bound containers mtl parsers prelude-extras 11 | QuickCheck trifecta unordered-containers 12 | ]; 13 | license = stdenv.lib.licenses.bsd3; 14 | } 15 | -------------------------------------------------------------------------------- /code/old/prototypes/frag/frag.cabal: -------------------------------------------------------------------------------- 1 | name: frag 2 | version: 0.1.0.0 3 | -- synopsis: 4 | -- description: 5 | license: BSD3 6 | license-file: LICENSE 7 | author: Dave Laing 8 | maintainer: dave.laing.80@gmail.com 9 | -- copyright: 10 | category: Language 11 | build-type: Simple 12 | -- extra-source-files: 13 | cabal-version: >=1.10 14 | 15 | library 16 | exposed-modules: Term, TermF, TermL 17 | -- other-modules: 18 | -- other-extensions: 19 | build-depends: QuickCheck >=2.8 && <2.9 20 | , ansi-wl-pprint >= 0.6 && < 0.7 21 | , base >=4.8 && <4.9 22 | , bound >=1.0 && <1.1 23 | , parsers 24 | , prelude-extras >=0.4 && <0.5 25 | , trifecta 26 | , unordered-containers 27 | , containers 28 | , mtl 29 | hs-source-dirs: src 30 | default-language: Haskell2010 31 | -------------------------------------------------------------------------------- /code/old/prototypes/frag/shell.nix: -------------------------------------------------------------------------------- 1 | with (import {}).pkgs; 2 | let modifiedHaskellPackages = haskellPackages.override { 3 | overrides = self: super: { 4 | frag = self.callPackage ./. {}; 5 | }; 6 | }; 7 | in modifiedHaskellPackages.frag.env 8 | -------------------------------------------------------------------------------- /code/old/prototypes/lc-full/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /code/old/prototypes/lc-full/default.nix: -------------------------------------------------------------------------------- 1 | { mkDerivation, ansi-wl-pprint, base, bound, prelude-extras 2 | , QuickCheck, stdenv 3 | }: 4 | mkDerivation { 5 | pname = "lc"; 6 | version = "0.1.0.0"; 7 | src = ./.; 8 | libraryHaskellDepends = [ 9 | ansi-wl-pprint base bound prelude-extras QuickCheck 10 | ]; 11 | license = stdenv.lib.licenses.bsd3; 12 | } 13 | -------------------------------------------------------------------------------- /code/old/prototypes/lc-full/lc-full.cabal: -------------------------------------------------------------------------------- 1 | name: lc-full 2 | version: 0.1.0.0 3 | -- synopsis: 4 | -- description: 5 | license: BSD3 6 | license-file: LICENSE 7 | author: Dave Laing 8 | maintainer: dave.laing.80@gmail.com 9 | -- copyright: 10 | category: Language 11 | build-type: Simple 12 | -- extra-source-files: 13 | cabal-version: >=1.10 14 | 15 | library 16 | exposed-modules: Term.AST 17 | , Term.Pretty 18 | -- other-modules: 19 | -- other-extensions: 20 | build-depends: base >=4.8 && <4.9 21 | , bound >=1.0 && <1.1 22 | , prelude-extras >=0.4 && <0.5 23 | , ansi-wl-pprint >= 0.6 && < 0.7 24 | , QuickCheck >=2.8 && <2.9 25 | hs-source-dirs: src 26 | default-language: Haskell2010 27 | -------------------------------------------------------------------------------- /code/old/prototypes/lc-full/shell.nix: -------------------------------------------------------------------------------- 1 | with (import {}).pkgs; 2 | let modifiedHaskellPackages = haskellPackages.override { 3 | overrides = self: super: { 4 | lc-full = self.callPackage ./. {}; 5 | }; 6 | }; 7 | in modifiedHaskellPackages.lc-full.env 8 | -------------------------------------------------------------------------------- /code/old/prototypes/lc-named/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /code/old/prototypes/lc-named/default.nix: -------------------------------------------------------------------------------- 1 | { mkDerivation, base, bound, prelude-extras, QuickCheck, stdenv }: 2 | mkDerivation { 3 | pname = "lc-named"; 4 | version = "0.1.0.0"; 5 | src = ./.; 6 | libraryHaskellDepends = [ base bound prelude-extras QuickCheck ]; 7 | license = stdenv.lib.licenses.bsd3; 8 | } 9 | -------------------------------------------------------------------------------- /code/old/prototypes/lc-named/lc-named.cabal: -------------------------------------------------------------------------------- 1 | name: lc-named 2 | version: 0.1.0.0 3 | -- synopsis: 4 | -- description: 5 | license: BSD3 6 | license-file: LICENSE 7 | author: Dave Laing 8 | maintainer: dave.laing.80@gmail.com 9 | -- copyright: 10 | category: Language 11 | build-type: Simple 12 | -- extra-source-files: 13 | cabal-version: >=1.10 14 | 15 | library 16 | exposed-modules: Term.AST 17 | -- other-modules: 18 | -- other-extensions: 19 | build-depends: base >=4.8 && <4.9 20 | , bound >=1.0 && <1.1 21 | , prelude-extras >=0.4 && <0.5 22 | , QuickCheck >=2.8 && <2.9 23 | hs-source-dirs: src 24 | default-language: Haskell2010 25 | -------------------------------------------------------------------------------- /code/old/prototypes/lc-named/shell.nix: -------------------------------------------------------------------------------- 1 | with (import {}).pkgs; 2 | let modifiedHaskellPackages = haskellPackages.override { 3 | overrides = self: super: { 4 | lc-named = self.callPackage ./. {}; 5 | }; 6 | }; 7 | in modifiedHaskellPackages.lc-named.env 8 | -------------------------------------------------------------------------------- /code/old/prototypes/lc/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /code/old/prototypes/lc/default.nix: -------------------------------------------------------------------------------- 1 | { mkDerivation, ansi-wl-pprint, base, bound, prelude-extras 2 | , QuickCheck, stdenv 3 | }: 4 | mkDerivation { 5 | pname = "lc"; 6 | version = "0.1.0.0"; 7 | src = ./.; 8 | libraryHaskellDepends = [ 9 | ansi-wl-pprint base bound prelude-extras QuickCheck 10 | ]; 11 | license = stdenv.lib.licenses.bsd3; 12 | } 13 | -------------------------------------------------------------------------------- /code/old/prototypes/lc/lc.cabal: -------------------------------------------------------------------------------- 1 | name: lc 2 | version: 0.1.0.0 3 | -- synopsis: 4 | -- description: 5 | license: BSD3 6 | license-file: LICENSE 7 | author: Dave Laing 8 | maintainer: dave.laing.80@gmail.com 9 | -- copyright: 10 | category: Language 11 | build-type: Simple 12 | -- extra-source-files: 13 | cabal-version: >=1.10 14 | 15 | library 16 | exposed-modules: Term.AST 17 | , Term.Pretty 18 | -- other-modules: 19 | -- other-extensions: 20 | build-depends: base >=4.8 && <4.9 21 | , bound >=1.0 && <1.1 22 | , prelude-extras >=0.4 && <0.5 23 | , ansi-wl-pprint >= 0.6 && < 0.7 24 | , QuickCheck >=2.8 && <2.9 25 | hs-source-dirs: src 26 | default-language: Haskell2010 27 | -------------------------------------------------------------------------------- /code/old/prototypes/lc/shell.nix: -------------------------------------------------------------------------------- 1 | with (import {}).pkgs; 2 | let modifiedHaskellPackages = haskellPackages.override { 3 | overrides = self: super: { 4 | lc = self.callPackage ./. {}; 5 | }; 6 | }; 7 | in modifiedHaskellPackages.lc.env 8 | -------------------------------------------------------------------------------- /code/old/prototypes/little/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /code/old/prototypes/little/default.nix: -------------------------------------------------------------------------------- 1 | { mkDerivation, base, bifunctors, errors, generics-eot, lens 2 | , profunctors, QuickCheck, stdenv 3 | }: 4 | mkDerivation { 5 | pname = "little"; 6 | version = "0.1.0.0"; 7 | src = ./.; 8 | libraryHaskellDepends = [ 9 | base bifunctors errors generics-eot lens profunctors QuickCheck 10 | ]; 11 | license = stdenv.lib.licenses.bsd3; 12 | } 13 | -------------------------------------------------------------------------------- /code/old/prototypes/little/shell.nix: -------------------------------------------------------------------------------- 1 | with (import {}).pkgs; 2 | let modifiedHaskellPackages = haskellPackages.override { 3 | overrides = self: super: { 4 | little = self.callPackage ./. {}; 5 | }; 6 | }; 7 | in modifiedHaskellPackages.little.env 8 | -------------------------------------------------------------------------------- /code/old/prototypes/nb/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /code/old/prototypes/nb/default.nix: -------------------------------------------------------------------------------- 1 | { mkDerivation, ansi-wl-pprint, base, bound, containers, lens, mtl 2 | , parsers, prelude-extras, QuickCheck, stdenv, trifecta 3 | , unordered-containers 4 | }: 5 | mkDerivation { 6 | pname = "nb"; 7 | version = "0.1.0.0"; 8 | src = ./.; 9 | libraryHaskellDepends = [ 10 | ansi-wl-pprint base bound containers lens mtl parsers 11 | prelude-extras QuickCheck trifecta unordered-containers 12 | ]; 13 | license = stdenv.lib.licenses.bsd3; 14 | } 15 | -------------------------------------------------------------------------------- /code/old/prototypes/nb/shell.nix: -------------------------------------------------------------------------------- 1 | with (import {}).pkgs; 2 | let modifiedHaskellPackages = haskellPackages.override { 3 | overrides = self: super: { 4 | nb = self.callPackage ./. {}; 5 | }; 6 | }; 7 | in modifiedHaskellPackages.nb.env 8 | -------------------------------------------------------------------------------- /code/old/prototypes/proap/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /code/old/prototypes/proap/Setup.hs.save0: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /code/old/prototypes/proap/Setup.hs.save1: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /code/old/prototypes/proap/default.nix: -------------------------------------------------------------------------------- 1 | { mkDerivation, base, bifunctors, generics-eot, lens, profunctors 2 | , QuickCheck, semigroupoids, semigroups, stdenv 3 | }: 4 | mkDerivation { 5 | pname = "proap"; 6 | version = "0.1.0.0"; 7 | src = ./.; 8 | libraryHaskellDepends = [ 9 | base bifunctors generics-eot lens profunctors QuickCheck 10 | semigroupoids semigroups 11 | ]; 12 | license = stdenv.lib.licenses.bsd3; 13 | } 14 | -------------------------------------------------------------------------------- /code/old/prototypes/proap/proap.cabal.save0: -------------------------------------------------------------------------------- 1 | -- Initial proap.cabal generated by cabal init. For further documentation, 2 | -- see http://haskell.org/cabal/users-guide/ 3 | 4 | name: proap 5 | version: 0.1.0.0 6 | -- synopsis: 7 | -- description: 8 | license: BSD3 9 | license-file: LICENSE 10 | author: Dave Laing 11 | maintainer: dave.laing.80@gmail.com 12 | -- copyright: 13 | -- category: 14 | build-type: Simple 15 | -- extra-source-files: 16 | cabal-version: >=1.10 17 | 18 | library 19 | exposed-modules: Div, GenShrink, GenShrink.Test 20 | -- other-modules: 21 | -- other-extensions: 22 | build-depends: base >=4.8 && <4.9, lens >=4.13 && <4.14, bifunctors >=5.2 && <5.3, semigroupoids >=5.0 && <5.1, profunctors >=5.2 && <5.3 23 | hs-source-dirs: src 24 | default-language: Haskell2010 25 | -------------------------------------------------------------------------------- /code/old/prototypes/proap/proap.cabal.save1: -------------------------------------------------------------------------------- 1 | -- Initial proap.cabal generated by cabal init. For further documentation, 2 | -- see http://haskell.org/cabal/users-guide/ 3 | 4 | name: proap 5 | version: 0.1.0.0 6 | -- synopsis: 7 | -- description: 8 | -- license: 9 | license-file: LICENSE 10 | author: Dave Laing 11 | maintainer: dave.laing.80@gmail.com 12 | -- copyright: 13 | -- category: 14 | build-type: Simple 15 | -- extra-source-files: 16 | cabal-version: >=1.10 17 | 18 | library 19 | exposed-modules: Div, GenShrink, GenShrink.Test 20 | -- other-modules: 21 | other-extensions: FlexibleInstances, FlexibleContexts, MultiParamTypeClasses, RankNTypes, ScopedTypeVariables 22 | build-depends: base >=4.8 && <4.9, lens >=4.13 && <4.14, bifunctors >=5.2 && <5.3, semigroupoids >=5.0 && <5.1, profunctors >=5.2 && <5.3, QuickCheck >=2.8 && <2.9 23 | hs-source-dirs: src 24 | default-language: Haskell2010 -------------------------------------------------------------------------------- /code/old/prototypes/proap/shell.nix: -------------------------------------------------------------------------------- 1 | with (import {}).pkgs; 2 | let modifiedHaskellPackages = haskellPackages.override { 3 | overrides = self: super: { 4 | proap = self.callPackage ./. {}; 5 | }; 6 | }; 7 | in modifiedHaskellPackages.proap.env 8 | -------------------------------------------------------------------------------- /code/old/prototypes/prod/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /code/old/prototypes/prod/default.nix: -------------------------------------------------------------------------------- 1 | { mkDerivation, ansi-wl-pprint, base, bound, containers, mtl 2 | , parsers, prelude-extras, QuickCheck, stdenv, trifecta 3 | , unordered-containers 4 | }: 5 | mkDerivation { 6 | pname = "type"; 7 | version = "0.1.0.0"; 8 | src = ./.; 9 | libraryHaskellDepends = [ 10 | ansi-wl-pprint base bound containers mtl parsers prelude-extras 11 | QuickCheck trifecta unordered-containers 12 | ]; 13 | license = stdenv.lib.licenses.bsd3; 14 | } 15 | -------------------------------------------------------------------------------- /code/old/prototypes/prod/shell.nix: -------------------------------------------------------------------------------- 1 | with (import {}).pkgs; 2 | let modifiedHaskellPackages = haskellPackages.override { 3 | overrides = self: super: { 4 | prod = self.callPackage ./. {}; 5 | }; 6 | }; 7 | in modifiedHaskellPackages.prod.env 8 | -------------------------------------------------------------------------------- /code/old/prototypes/prod/src/Data.hs: -------------------------------------------------------------------------------- 1 | module Data where 2 | -------------------------------------------------------------------------------- /code/old/prototypes/prod/src/Decl.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DeriveFunctor #-} 2 | {-# LANGUAGE DeriveFoldable #-} 3 | {-# LANGUAGE DeriveTraversable #-} 4 | module Decl where 5 | 6 | import Control.Monad 7 | 8 | import Bound 9 | import Prelude.Extras 10 | 11 | data Decl l n t d = 12 | Decl d 13 | | DclLoc l (Decl l n t d) 14 | | Prod [t] 15 | deriving (Eq, Ord, Show, Functor, Foldable, Traversable) 16 | 17 | instance (Eq l, Eq t) => Eq1 (Decl l n t) where 18 | (==#) = (==) 19 | 20 | instance (Ord l, Ord t) => Ord1 (Decl l n t) where 21 | compare1 = compare 22 | 23 | instance (Show l, Show t) => Show1 (Decl l n t) where 24 | showsPrec1 = showsPrec 25 | 26 | instance Applicative (Decl l n t) where 27 | pure = return 28 | (<*>) = ap 29 | 30 | instance Monad (Decl l n t) where 31 | return = Decl 32 | 33 | Decl d >>= f = f d 34 | DclLoc l d >>= f = DclLoc l (d >>= f) 35 | Prod ts >>= _ = Prod ts 36 | 37 | -------------------------------------------------------------------------------- /code/old/prototypes/prod/src/Type.hs: -------------------------------------------------------------------------------- 1 | module Type where 2 | 3 | import Bound 4 | import Bound.Name 5 | 6 | import Decl 7 | 8 | data Type l n d = 9 | TyInt 10 | | TyBool 11 | | TyArr (Type l n d) (Type l n d) 12 | | TyDecl d 13 | deriving (Eq, Ord, Show) 14 | 15 | -------------------------------------------------------------------------------- /code/old/prototypes/syntax/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /code/old/prototypes/syntax/default.nix: -------------------------------------------------------------------------------- 1 | { mkDerivation, ansi-wl-pprint, base, bound, parsers 2 | , prelude-extras, QuickCheck, stdenv, trifecta 3 | , unordered-containers 4 | }: 5 | mkDerivation { 6 | pname = "syntax"; 7 | version = "0.1.0.0"; 8 | src = ./.; 9 | libraryHaskellDepends = [ 10 | ansi-wl-pprint base bound parsers prelude-extras QuickCheck 11 | trifecta unordered-containers 12 | ]; 13 | license = stdenv.lib.licenses.bsd3; 14 | } 15 | -------------------------------------------------------------------------------- /code/old/prototypes/syntax/shell.nix: -------------------------------------------------------------------------------- 1 | with (import {}).pkgs; 2 | let modifiedHaskellPackages = haskellPackages.override { 3 | overrides = self: super: { 4 | syntax = self.callPackage ./. {}; 5 | }; 6 | }; 7 | in modifiedHaskellPackages.syntax.env 8 | -------------------------------------------------------------------------------- /code/old/prototypes/syntax/syntax.cabal: -------------------------------------------------------------------------------- 1 | name: syntax 2 | version: 0.1.0.0 3 | -- synopsis: 4 | -- description: 5 | license: BSD3 6 | license-file: LICENSE 7 | author: Dave Laing 8 | maintainer: dave.laing.80@gmail.com 9 | -- copyright: 10 | category: Language 11 | build-type: Simple 12 | -- extra-source-files: 13 | cabal-version: >=1.10 14 | 15 | library 16 | exposed-modules: Term 17 | , Term.Pretty 18 | , Term.Parser 19 | -- other-modules: 20 | -- other-extensions: 21 | build-depends: base >=4.8 && <4.9 22 | , bound >=1.0 && <1.1 23 | , prelude-extras >=0.4 && <0.5 24 | , ansi-wl-pprint >= 0.6 && < 0.7 25 | , unordered-containers 26 | , parsers 27 | , trifecta 28 | , QuickCheck >=2.8 && <2.9 29 | hs-source-dirs: src 30 | default-language: Haskell2010 31 | -------------------------------------------------------------------------------- /code/old/prototypes/type/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /code/old/prototypes/type/default.nix: -------------------------------------------------------------------------------- 1 | { mkDerivation, ansi-wl-pprint, base, bound, containers, mtl 2 | , parsers, prelude-extras, QuickCheck, stdenv, trifecta 3 | , unordered-containers 4 | }: 5 | mkDerivation { 6 | pname = "type"; 7 | version = "0.1.0.0"; 8 | src = ./.; 9 | libraryHaskellDepends = [ 10 | ansi-wl-pprint base bound containers mtl parsers prelude-extras 11 | QuickCheck trifecta unordered-containers 12 | ]; 13 | license = stdenv.lib.licenses.bsd3; 14 | } 15 | -------------------------------------------------------------------------------- /code/old/prototypes/type/shell.nix: -------------------------------------------------------------------------------- 1 | with (import {}).pkgs; 2 | let modifiedHaskellPackages = haskellPackages.override { 3 | overrides = self: super: { 4 | type = self.callPackage ./. {}; 5 | }; 6 | }; 7 | in modifiedHaskellPackages.type.env 8 | -------------------------------------------------------------------------------- /code/old/prototypes/type/src/Type.hs: -------------------------------------------------------------------------------- 1 | module Type where 2 | 3 | data Type = 4 | TyInt 5 | | TyBool 6 | | TyArr Type Type 7 | deriving (Eq, Ord, Show) 8 | -------------------------------------------------------------------------------- /code/old/unityped/b/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /code/old/unityped/b/default.nix: -------------------------------------------------------------------------------- 1 | { mkDerivation, ansi-wl-pprint, base, haskeline, lens, parsers 2 | , QuickCheck, stdenv, tasty, tasty-quickcheck, trifecta 3 | , unordered-containers 4 | }: 5 | mkDerivation { 6 | pname = "b"; 7 | version = "0.1.0.0"; 8 | src = ./.; 9 | isLibrary = true; 10 | isExecutable = true; 11 | libraryHaskellDepends = [ 12 | ansi-wl-pprint base lens parsers QuickCheck trifecta 13 | unordered-containers 14 | ]; 15 | executableHaskellDepends = [ base haskeline ]; 16 | testHaskellDepends = [ base QuickCheck tasty tasty-quickcheck ]; 17 | license = stdenv.lib.licenses.bsd3; 18 | } 19 | -------------------------------------------------------------------------------- /code/old/unityped/b/repl/Main.hs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Control.Monad.IO.Class 4 | import System.Console.Haskeline 5 | 6 | import Text.PrettyPrint.ANSI.Leijen (putDoc, (<>), line) 7 | 8 | import UI 9 | 10 | main :: IO () 11 | main = runInputT defaultSettings loop 12 | where 13 | loop :: InputT IO () 14 | loop = do 15 | i <- getInputLine "> " 16 | case i of 17 | Nothing -> return () 18 | Just "quit" -> return () 19 | Just i' -> do 20 | liftIO . putDoc . (<> line) . parseAndEval $ i' 21 | loop 22 | -------------------------------------------------------------------------------- /code/old/unityped/b/shell.nix: -------------------------------------------------------------------------------- 1 | { nixpkgs ? import {}, compiler ? "default" }: 2 | 3 | let 4 | 5 | inherit (nixpkgs) pkgs; 6 | 7 | f = { mkDerivation, ansi-wl-pprint, base, haskeline, lens 8 | , parsers, QuickCheck, stdenv, tasty, tasty-quickcheck, trifecta 9 | , unordered-containers 10 | }: 11 | mkDerivation { 12 | pname = "b"; 13 | version = "0.1.0.0"; 14 | src = ./.; 15 | isLibrary = true; 16 | isExecutable = true; 17 | libraryHaskellDepends = [ 18 | ansi-wl-pprint base lens parsers QuickCheck trifecta 19 | unordered-containers 20 | ]; 21 | executableHaskellDepends = [ base haskeline ]; 22 | testHaskellDepends = [ base QuickCheck tasty tasty-quickcheck ]; 23 | license = stdenv.lib.licenses.bsd3; 24 | }; 25 | 26 | haskellPackages = if compiler == "default" 27 | then pkgs.haskellPackages 28 | else pkgs.haskell.packages.${compiler}; 29 | 30 | drv = haskellPackages.callPackage f {}; 31 | 32 | in 33 | 34 | if pkgs.lib.inNixShell then drv.env else drv 35 | -------------------------------------------------------------------------------- /code/old/unityped/b/src/Term.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TemplateHaskell #-} 2 | module Term where 3 | 4 | import Control.Lens.TH 5 | 6 | data Term = 7 | TmFalse 8 | | TmTrue 9 | | TmIf Term Term Term 10 | deriving (Eq, Ord, Show) 11 | 12 | makeClassyPrisms ''Term 13 | 14 | size :: Term -> Int 15 | size TmFalse = 1 16 | size TmTrue = 1 17 | size (TmIf t1 t2 t3) = 1 + size t1 + size t2 + size t3 18 | -------------------------------------------------------------------------------- /code/old/unityped/b/src/Term/Eval/BigStep.hs: -------------------------------------------------------------------------------- 1 | module Term.Eval.BigStep where 2 | 3 | import Control.Lens (preview) 4 | import Data.Foldable (asum) 5 | import Data.Maybe (fromMaybe) 6 | 7 | import Term 8 | import Term.Eval.Value (value) 9 | 10 | eIfTrue :: (Term -> Maybe Term) 11 | -> Term 12 | -> Maybe Term 13 | eIfTrue step t = do 14 | (t1, t2, _) <- preview _TmIf t 15 | u1 <- step t1 16 | preview _TmTrue u1 17 | step t2 18 | 19 | eIfFalse :: (Term -> Maybe Term) 20 | -> Term 21 | -> Maybe Term 22 | eIfFalse step t = do 23 | (t1, _, t3) <- preview _TmIf t 24 | u1 <- step t1 25 | preview _TmFalse u1 26 | step t3 27 | 28 | bigStepRules :: [Term -> Maybe Term] 29 | bigStepRules = 30 | [ value 31 | , eIfTrue bigStep 32 | , eIfFalse bigStep 33 | ] 34 | 35 | bigStep :: Term 36 | -> Maybe Term 37 | bigStep t = 38 | asum . 39 | map ($ t) $ 40 | bigStepRules 41 | 42 | bEval :: Term 43 | -> Term 44 | bEval t = 45 | fromMaybe t . 46 | bigStep $ 47 | t 48 | 49 | -------------------------------------------------------------------------------- /code/old/unityped/b/src/Term/Eval/SmallStep.hs: -------------------------------------------------------------------------------- 1 | module Term.Eval.SmallStep where 2 | 3 | import Control.Lens (preview) 4 | import Data.Foldable (asum) 5 | 6 | import Term 7 | 8 | eIfTrue :: Term 9 | -> Maybe Term 10 | eIfTrue t = do 11 | (t1, t2, _) <- preview _TmIf t 12 | preview _TmTrue t1 13 | return t2 14 | 15 | eIfFalse :: Term 16 | -> Maybe Term 17 | eIfFalse t = do 18 | (t1, _, t3) <- preview _TmIf t 19 | preview _TmFalse t1 20 | return t3 21 | 22 | eIf :: (Term -> Maybe Term) 23 | -> Term 24 | -> Maybe Term 25 | eIf step t = do 26 | (t1, t2, t3) <- preview _TmIf t 27 | u1 <- step t1 28 | return $ TmIf u1 t2 t3 29 | 30 | smallStepRules :: [Term -> Maybe Term] 31 | smallStepRules = 32 | [ eIfTrue 33 | , eIfFalse 34 | , eIf smallStep 35 | ] 36 | 37 | smallStep :: Term 38 | -> Maybe Term 39 | smallStep t = 40 | asum . 41 | map ($ t) $ 42 | smallStepRules 43 | 44 | sEval :: Term 45 | -> Term 46 | sEval t = case smallStep t of 47 | Nothing -> t 48 | Just u -> sEval u 49 | 50 | -------------------------------------------------------------------------------- /code/old/unityped/b/src/Term/Eval/Value.hs: -------------------------------------------------------------------------------- 1 | module Term.Eval.Value where 2 | 3 | import Data.Foldable (asum) 4 | 5 | import Term 6 | 7 | valueTmFalse :: Term 8 | -> Maybe Term 9 | valueTmFalse TmFalse = 10 | Just TmFalse 11 | valueTmFalse _ = 12 | Nothing 13 | 14 | valueTmTrue :: Term 15 | -> Maybe Term 16 | valueTmTrue TmTrue = 17 | Just TmTrue 18 | valueTmTrue _ = 19 | Nothing 20 | 21 | valueRules :: [Term -> Maybe Term] 22 | valueRules = 23 | [ valueTmFalse 24 | , valueTmTrue 25 | ] 26 | 27 | value :: Term 28 | -> Maybe Term 29 | value tm = 30 | asum . 31 | map ($ tm) $ 32 | valueRules 33 | -------------------------------------------------------------------------------- /code/old/unityped/b/src/UI.hs: -------------------------------------------------------------------------------- 1 | module UI where 2 | 3 | import Text.PrettyPrint.ANSI.Leijen (Doc) 4 | 5 | import Term.Parse 6 | import Term.Pretty 7 | import Term.Eval.SmallStep 8 | 9 | parseAndEval :: String -> Doc 10 | parseAndEval s = 11 | case parseTermString s of 12 | Left e -> e 13 | Right t -> printTerm . sEval $ t 14 | -------------------------------------------------------------------------------- /code/old/unityped/b/tests/Test.hs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Test.Tasty 4 | 5 | import Test.Term (termTests) 6 | 7 | main :: IO () 8 | main = defaultMain tests 9 | 10 | tests :: TestTree 11 | tests = testGroup "tests" [ 12 | termTests 13 | ] 14 | -------------------------------------------------------------------------------- /code/old/unityped/b/tests/Test/Term.hs: -------------------------------------------------------------------------------- 1 | module Test.Term where 2 | 3 | import Test.Tasty 4 | 5 | import Test.Term.Text (textTests) 6 | import Test.Term.Eval (evalTests) 7 | 8 | termTests :: TestTree 9 | termTests = testGroup "term" [ 10 | textTests 11 | , evalTests 12 | ] 13 | -------------------------------------------------------------------------------- /code/old/unityped/b/tests/Test/Term/Text.hs: -------------------------------------------------------------------------------- 1 | module Test.Term.Text where 2 | 3 | import Test.Tasty 4 | import Test.Tasty.QuickCheck 5 | 6 | import Term.Gen 7 | import Term.Parse 8 | import Term.Pretty 9 | 10 | textTests :: TestTree 11 | textTests = 12 | testGroup "text" [ 13 | testProperty "roundTrip" propRoundTrip 14 | ] 15 | 16 | propRoundTrip :: AnyTerm 17 | -> Property 18 | propRoundTrip (AnyTerm t) = 19 | case roundTrip t of 20 | Left _ -> property False 21 | Right u -> u === t 22 | where 23 | roundTrip = 24 | parseTermString . 25 | prettyString 26 | -------------------------------------------------------------------------------- /code/old/unityped/i/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /code/old/unityped/i/default.nix: -------------------------------------------------------------------------------- 1 | { mkDerivation, ansi-wl-pprint, base, haskeline, lens, parsers 2 | , QuickCheck, stdenv, tasty, tasty-quickcheck, transformers 3 | , trifecta, unordered-containers 4 | }: 5 | mkDerivation { 6 | pname = "i"; 7 | version = "0.1.0.0"; 8 | src = ./.; 9 | isLibrary = true; 10 | isExecutable = true; 11 | libraryHaskellDepends = [ 12 | ansi-wl-pprint base lens parsers QuickCheck trifecta 13 | unordered-containers 14 | ]; 15 | executableHaskellDepends = [ 16 | ansi-wl-pprint base haskeline transformers 17 | ]; 18 | testHaskellDepends = [ base QuickCheck tasty tasty-quickcheck ]; 19 | license = stdenv.lib.licenses.bsd3; 20 | } 21 | -------------------------------------------------------------------------------- /code/old/unityped/i/repl/Main.hs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Control.Monad.IO.Class 4 | import System.Console.Haskeline 5 | 6 | import Text.PrettyPrint.ANSI.Leijen (putDoc, (<>), line) 7 | 8 | import UI 9 | 10 | main :: IO () 11 | main = runInputT defaultSettings loop 12 | where 13 | loop :: InputT IO () 14 | loop = do 15 | i <- getInputLine "> " 16 | case i of 17 | Nothing -> return () 18 | Just "quit" -> return () 19 | Just i' -> do 20 | liftIO . putDoc . (<> line) . parseAndEval $ i' 21 | loop 22 | -------------------------------------------------------------------------------- /code/old/unityped/i/src/Term.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TemplateHaskell #-} 2 | module Term where 3 | 4 | import Control.Lens.TH 5 | 6 | data Term = 7 | TmInt Int 8 | | TmAdd Term Term 9 | | TmSub Term Term 10 | | TmMul Term Term 11 | | TmExp Term Term 12 | deriving (Eq, Ord, Show) 13 | 14 | makeClassyPrisms ''Term 15 | 16 | size :: Term -> Int 17 | size (TmInt _) = 1 18 | size (TmAdd t1 t2) = 1 + size t1 + size t2 19 | size (TmSub t1 t2) = 1 + size t1 + size t2 20 | size (TmMul t1 t2) = 1 + size t1 + size t2 21 | size (TmExp t1 t2) = 1 + size t1 + size t2 22 | -------------------------------------------------------------------------------- /code/old/unityped/i/src/Term/Eval/Value.hs: -------------------------------------------------------------------------------- 1 | module Term.Eval.Value where 2 | 3 | import Data.Foldable (asum) 4 | 5 | import Term 6 | 7 | valueTmInt :: Term 8 | -> Maybe Term 9 | valueTmInt (TmInt i) = 10 | Just $ TmInt i 11 | valueTmInt _ = 12 | Nothing 13 | 14 | valueRules :: [Term -> Maybe Term] 15 | valueRules = 16 | [valueTmInt] 17 | 18 | value :: Term 19 | -> Maybe Term 20 | value tm = 21 | asum . 22 | map ($ tm) $ 23 | valueRules 24 | -------------------------------------------------------------------------------- /code/old/unityped/i/src/UI.hs: -------------------------------------------------------------------------------- 1 | module UI where 2 | 3 | import Text.PrettyPrint.ANSI.Leijen (Doc) 4 | 5 | import Term.Parse 6 | import Term.Pretty 7 | import Term.Eval.SmallStep 8 | 9 | parseAndEval :: String -> Doc 10 | parseAndEval s = 11 | case parseTermString s of 12 | Left e -> e 13 | Right t -> prettyTerm . sEval $ t 14 | -------------------------------------------------------------------------------- /code/old/unityped/i/tests/Test.hs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Test.Tasty 4 | 5 | import Test.Term (termTests) 6 | 7 | main :: IO () 8 | main = defaultMain tests 9 | 10 | tests :: TestTree 11 | tests = testGroup "tests" [ 12 | termTests 13 | ] 14 | -------------------------------------------------------------------------------- /code/old/unityped/i/tests/Test/Term.hs: -------------------------------------------------------------------------------- 1 | module Test.Term where 2 | 3 | import Test.Tasty 4 | 5 | import Test.Term.Text (textTests) 6 | import Test.Term.Eval (evalTests) 7 | 8 | termTests :: TestTree 9 | termTests = testGroup "term" [ 10 | textTests 11 | , evalTests 12 | ] 13 | -------------------------------------------------------------------------------- /code/old/unityped/i/tests/Test/Term/Text.hs: -------------------------------------------------------------------------------- 1 | module Test.Term.Text where 2 | 3 | import Test.Tasty 4 | import Test.Tasty.QuickCheck 5 | 6 | import Term.Gen 7 | import Term.Parse 8 | import Term.Pretty 9 | 10 | textTests :: TestTree 11 | textTests = 12 | testGroup "text" [ 13 | testProperty "roundTrip" propRoundTrip 14 | ] 15 | 16 | propRoundTrip :: AnyTerm 17 | -> Property 18 | propRoundTrip (AnyTerm t) = 19 | case roundTrip t of 20 | Left _ -> property False 21 | Right u -> u === t 22 | where 23 | roundTrip = 24 | parseTermString . 25 | prettyString 26 | -------------------------------------------------------------------------------- /code/old/unityped/lc/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /code/old/unityped/lc/default.nix: -------------------------------------------------------------------------------- 1 | { mkDerivation, ansi-wl-pprint, base, bound, haskeline, lens 2 | , parsers, prelude-extras, QuickCheck, stdenv, tasty 3 | , tasty-quickcheck, transformers, trifecta, unordered-containers 4 | }: 5 | mkDerivation { 6 | pname = "lc"; 7 | version = "0.1.0.0"; 8 | src = ./.; 9 | isLibrary = true; 10 | isExecutable = true; 11 | libraryHaskellDepends = [ 12 | ansi-wl-pprint base bound lens parsers prelude-extras QuickCheck 13 | trifecta unordered-containers 14 | ]; 15 | executableHaskellDepends = [ 16 | ansi-wl-pprint base haskeline transformers 17 | ]; 18 | testHaskellDepends = [ base QuickCheck tasty tasty-quickcheck ]; 19 | license = stdenv.lib.licenses.bsd3; 20 | } 21 | -------------------------------------------------------------------------------- /code/old/unityped/lc/repl/Main.hs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Control.Monad.IO.Class 4 | import System.Console.Haskeline 5 | 6 | import Text.PrettyPrint.ANSI.Leijen (putDoc, (<>), line) 7 | 8 | import UI 9 | 10 | main :: IO () 11 | main = runInputT defaultSettings loop 12 | where 13 | loop :: InputT IO () 14 | loop = do 15 | i <- getInputLine "> " 16 | case i of 17 | Nothing -> return () 18 | Just "quit" -> return () 19 | Just i' -> do 20 | liftIO . putDoc . (<> line) . parseAndEval $ i' 21 | loop 22 | -------------------------------------------------------------------------------- /code/old/unityped/lc/src/Term/Eval/BigStep.hs: -------------------------------------------------------------------------------- 1 | module Term.Eval.BigStep where 2 | 3 | import Control.Lens (preview) 4 | import Data.Foldable (asum) 5 | import Data.Maybe (fromMaybe) 6 | 7 | import Bound 8 | 9 | import Term 10 | import Term.Eval.Value (value) 11 | 12 | eApp :: (Term n a -> Maybe (Term n a)) 13 | -> Term n a 14 | -> Maybe (Term n a) 15 | eApp step t = do 16 | (f, x) <- preview _TmApp t 17 | f' <- step f 18 | (_, e) <- preview _TmLam f' 19 | step $ instantiate1 x e 20 | 21 | bigStepRules :: [Term n a -> Maybe (Term n a)] 22 | bigStepRules = 23 | [ value 24 | , eApp bigStep 25 | ] 26 | 27 | bigStep :: Term n a 28 | -> Maybe (Term n a) 29 | bigStep t = 30 | asum . 31 | map ($ t) $ 32 | bigStepRules 33 | 34 | bEval :: Term n a 35 | -> Term n a 36 | bEval t = 37 | fromMaybe t . 38 | bigStep $ 39 | t 40 | 41 | -------------------------------------------------------------------------------- /code/old/unityped/lc/src/Term/Eval/Value.hs: -------------------------------------------------------------------------------- 1 | module Term.Eval.Value where 2 | 3 | import Data.Foldable (asum) 4 | 5 | import Term 6 | 7 | -- TODO this is not really a variable, at least if we're generating closed 8 | -- terms, perhaps need to fix up the generation or the tests 9 | valueTmVar :: Term n a 10 | -> Maybe (Term n a) 11 | valueTmVar (TmVar x) = 12 | Just $ TmVar x 13 | valueTmVar _ = 14 | Nothing 15 | 16 | valueTmLam :: Term n a 17 | -> Maybe (Term n a) 18 | valueTmLam (TmLam n e) = 19 | Just $ TmLam n e 20 | valueTmLam _ = 21 | Nothing 22 | 23 | valueRules :: [Term n a -> Maybe (Term n a)] 24 | valueRules = 25 | [ valueTmVar 26 | , valueTmLam 27 | ] 28 | 29 | value :: Term n a 30 | -> Maybe (Term n a) 31 | value tm = 32 | asum . 33 | map ($ tm) $ 34 | valueRules 35 | -------------------------------------------------------------------------------- /code/old/unityped/lc/src/UI.hs: -------------------------------------------------------------------------------- 1 | module UI where 2 | 3 | import Text.PrettyPrint.ANSI.Leijen (Doc) 4 | 5 | import Term.Parse 6 | import Term.Pretty 7 | import Term.Eval.SmallStep 8 | 9 | parseAndEval :: String -> Doc 10 | parseAndEval s = 11 | case parseTermString s of 12 | Left e -> e 13 | Right t -> prettyTerm . sEval $ t 14 | -------------------------------------------------------------------------------- /code/old/unityped/lc/tests/Test.hs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Test.Tasty 4 | 5 | import Test.Term (termTests) 6 | 7 | main :: IO () 8 | main = defaultMain tests 9 | 10 | tests :: TestTree 11 | tests = testGroup "tests" [ 12 | termTests 13 | ] 14 | -------------------------------------------------------------------------------- /code/old/unityped/lc/tests/Test/Term.hs: -------------------------------------------------------------------------------- 1 | module Test.Term where 2 | 3 | import Test.Tasty 4 | 5 | import Test.Term.Text (textTests) 6 | import Test.Term.Eval (evalTests) 7 | 8 | termTests :: TestTree 9 | termTests = testGroup "term" [ 10 | textTests 11 | , evalTests 12 | ] 13 | -------------------------------------------------------------------------------- /code/old/unityped/lc/tests/Test/Term/Text.hs: -------------------------------------------------------------------------------- 1 | module Test.Term.Text where 2 | 3 | import Test.Tasty 4 | import Test.Tasty.QuickCheck 5 | 6 | import Term.Gen 7 | import Term.Parse 8 | import Term.Pretty 9 | 10 | textTests :: TestTree 11 | textTests = 12 | testGroup "text" [ 13 | testProperty "roundTrip" propRoundTrip 14 | ] 15 | 16 | propRoundTrip :: AnyTerm 17 | -> Property 18 | propRoundTrip (AnyTerm t) = 19 | case roundTrip t of 20 | Left _ -> property False 21 | Right u -> u === t 22 | where 23 | roundTrip = 24 | parseTermString . 25 | prettyString 26 | -------------------------------------------------------------------------------- /code/old/unityped/n/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /code/old/unityped/n/default.nix: -------------------------------------------------------------------------------- 1 | { mkDerivation, ansi-wl-pprint, base, haskeline, lens, parsers 2 | , QuickCheck, stdenv, tasty, tasty-quickcheck, transformers 3 | , trifecta, unordered-containers 4 | }: 5 | mkDerivation { 6 | pname = "n"; 7 | version = "0.1.0.0"; 8 | src = ./.; 9 | isLibrary = true; 10 | isExecutable = true; 11 | libraryHaskellDepends = [ 12 | ansi-wl-pprint base lens parsers QuickCheck trifecta 13 | unordered-containers 14 | ]; 15 | executableHaskellDepends = [ 16 | ansi-wl-pprint base haskeline transformers 17 | ]; 18 | testHaskellDepends = [ base QuickCheck tasty tasty-quickcheck ]; 19 | license = stdenv.lib.licenses.bsd3; 20 | } 21 | -------------------------------------------------------------------------------- /code/old/unityped/n/repl/Main.hs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Control.Monad.IO.Class 4 | import System.Console.Haskeline 5 | 6 | import Text.PrettyPrint.ANSI.Leijen (putDoc, (<>), line) 7 | 8 | import UI 9 | 10 | main :: IO () 11 | main = runInputT defaultSettings loop 12 | where 13 | loop :: InputT IO () 14 | loop = do 15 | i <- getInputLine "> " 16 | case i of 17 | Nothing -> return () 18 | Just "quit" -> return () 19 | Just i' -> do 20 | liftIO . putDoc . (<> line) . parseAndEval $ i' 21 | loop 22 | -------------------------------------------------------------------------------- /code/old/unityped/n/src/Term.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TemplateHaskell #-} 2 | module Term where 3 | 4 | import Control.Lens.TH 5 | 6 | data Term = 7 | TmZero 8 | | TmSucc Term 9 | | TmPred Term 10 | deriving (Eq, Ord, Show) 11 | 12 | makeClassyPrisms ''Term 13 | 14 | size :: Term -> Int 15 | size TmZero = 1 16 | size (TmSucc t) = 1 + size t 17 | size (TmPred t) = 1 + size t 18 | -------------------------------------------------------------------------------- /code/old/unityped/n/src/Term/Eval/Value.hs: -------------------------------------------------------------------------------- 1 | module Term.Eval.Value where 2 | 3 | import Data.Foldable (asum) 4 | 5 | import Term 6 | 7 | valueTmZero :: Term 8 | -> Maybe Term 9 | valueTmZero TmZero = 10 | Just TmZero 11 | valueTmZero _ = 12 | Nothing 13 | 14 | valueTmSucc :: Term 15 | -> Maybe Term 16 | valueTmSucc (TmSucc tm) = 17 | TmSucc <$> value tm 18 | valueTmSucc _ = 19 | Nothing 20 | 21 | valueRules :: [Term -> Maybe Term] 22 | valueRules = 23 | [ valueTmZero 24 | , valueTmSucc 25 | ] 26 | 27 | value :: Term 28 | -> Maybe Term 29 | value tm = 30 | asum . 31 | map ($ tm) $ 32 | valueRules 33 | -------------------------------------------------------------------------------- /code/old/unityped/n/src/UI.hs: -------------------------------------------------------------------------------- 1 | module UI where 2 | 3 | import Text.PrettyPrint.ANSI.Leijen (Doc) 4 | 5 | import Term.Parse 6 | import Term.Pretty 7 | import Term.Eval.SmallStep 8 | 9 | parseAndEval :: String -> Doc 10 | parseAndEval s = 11 | case parseTermString s of 12 | Left e -> e 13 | Right t -> printTerm . sEval $ t 14 | -------------------------------------------------------------------------------- /code/old/unityped/n/tests/Test.hs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Test.Tasty 4 | 5 | import Test.Term (termTests) 6 | 7 | main :: IO () 8 | main = defaultMain tests 9 | 10 | tests :: TestTree 11 | tests = testGroup "tests" [ 12 | termTests 13 | ] 14 | -------------------------------------------------------------------------------- /code/old/unityped/n/tests/Test/Term.hs: -------------------------------------------------------------------------------- 1 | module Test.Term where 2 | 3 | import Test.Tasty 4 | 5 | import Test.Term.Text (textTests) 6 | import Test.Term.Eval (evalTests) 7 | 8 | termTests :: TestTree 9 | termTests = testGroup "term" [ 10 | textTests 11 | , evalTests 12 | ] 13 | -------------------------------------------------------------------------------- /code/old/unityped/n/tests/Test/Term/Text.hs: -------------------------------------------------------------------------------- 1 | module Test.Term.Text where 2 | 3 | import Test.Tasty 4 | import Test.Tasty.QuickCheck 5 | 6 | import Term.Gen 7 | import Term.Parse 8 | import Term.Pretty 9 | 10 | textTests :: TestTree 11 | textTests = 12 | testGroup "text" [ 13 | testProperty "roundTrip" propRoundTrip 14 | ] 15 | 16 | propRoundTrip :: AnyTerm 17 | -> Property 18 | propRoundTrip (AnyTerm t) = 19 | case roundTrip t of 20 | Left _ -> property False 21 | Right u -> u === t 22 | where 23 | roundTrip = 24 | parseTermString . 25 | prettyString 26 | -------------------------------------------------------------------------------- /talks/ylj16/.gitignore: -------------------------------------------------------------------------------- 1 | _minted-* 2 | auto 3 | _region* 4 | *.log 5 | *.aux 6 | *.nav 7 | *.out 8 | *.snm 9 | *.toc 10 | *.vrb 11 | 12 | 13 | -------------------------------------------------------------------------------- /talks/ylj16/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | pdflatex --shell-escape slides 3 | -------------------------------------------------------------------------------- /talks/ylj16/slides.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dalaing/little-languages/9f089f646a5344b8f7178700455a36a755d29b1f/talks/ylj16/slides.pdf --------------------------------------------------------------------------------