From 831d9c0737cd53be0b98f176f00c117de1ecc9ca Mon Sep 17 00:00:00 2001 From: tzlil Date: Sat, 15 Apr 2023 01:22:18 +0300 Subject: problem 1 --- .gitignore | 2 ++ flake.nix | 3 ++- lambda.cabal | 46 ++++++++++++++++++++-------------------------- src/HW.hs | 6 +++--- 4 files changed, 27 insertions(+), 30 deletions(-) diff --git a/.gitignore b/.gitignore index 82d9aa7..4fbd9bc 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ result *.pdf tests/runtests.log tests/out +.stack-work +*.lock diff --git a/flake.nix b/flake.nix index b32c2ca..57945c8 100644 --- a/flake.nix +++ b/flake.nix @@ -20,7 +20,8 @@ buildInputs = with pkgs.haskellPackages; [ cabal-install haskell-language-server - megaparsec + megaparsec + stack ]; }; treefmt = { diff --git a/lambda.cabal b/lambda.cabal index 68d5068..6189111 100644 --- a/lambda.cabal +++ b/lambda.cabal @@ -1,6 +1,6 @@ -cabal-version: 1.12 +cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.35.1. +-- This file has been generated from package.yaml by hpack version 0.35.2. -- -- see: https://github.com/sol/hpack @@ -11,39 +11,33 @@ maintainer: sedwards@cs.columbia.edu copyright: 2023 John Hui and Stephen Edwards license: BSD3 build-type: Simple -extra-source-files: README.md +extra-source-files: + README.md library exposed-modules: - AST - HW - Parse - - other-modules: Paths_lambda - hs-source-dirs: src - ghc-options: - -Wall -Wcompat -Widentities -Wincomplete-record-updates - -Wincomplete-uni-patterns -Wmissing-export-lists - -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints - + AST + HW + Parse + other-modules: + Paths_lambda + hs-source-dirs: + src + ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints build-depends: - base >=4.7 && <5 + base >=4.7 && <5 , containers , megaparsec - default-language: Haskell2010 executable plc - main-is: Main.hs - other-modules: Paths_lambda - hs-source-dirs: plc - ghc-options: - -Wall -Wcompat -Widentities -Wincomplete-record-updates - -Wincomplete-uni-patterns -Wmissing-export-lists - -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints - + main-is: Main.hs + other-modules: + Paths_lambda + hs-source-dirs: + plc + ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints build-depends: - base >=4.7 && <5 + base >=4.7 && <5 , lambda - default-language: Haskell2010 diff --git a/src/HW.hs b/src/HW.hs index 88fb1c2..ee26584 100644 --- a/src/HW.hs +++ b/src/HW.hs @@ -13,9 +13,9 @@ import Parse (parse) -- | Return the free variables in an expression fv :: Expr -> Set.Set String -fv _ = Set.singleton "UNIMPLEMENTED" -- Replace with your solution to problem 1 - - +fv (Var x) = Set.singleton x +fv (Lam x m) = x `Set.delete` (fv m) +fv (App m1 m2) = (fv m1) `Set.union` (fv m2) -- | Substitute n for x in e, avoiding name capture -- subst n x e e[x := n] -- cgit 1.4.1