Compare commits
3 Commits
d91a947186
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 153c179388 | |||
| 5b3392dab2 | |||
| 773fe1a9c3 |
@ -26,6 +26,7 @@ If you want to use Haskell then there is also a wrapper module ([[https://chalme
|
||||
(code =<< code (parse "\\x. x"))))
|
||||
#+end_src
|
||||
|
||||
\newpage
|
||||
* Exercises
|
||||
In order to pass this assignment you have to get at least four points.
|
||||
|
||||
@ -85,7 +86,7 @@ Test your implementation. Here are some test cases that must work:
|
||||
| ~z~ | $C(\lambda z . z)$ | $\text{case}\ z\ \text{of}\ \{ C(z) \rightarrow z \}$ | $\text{case}\ C(\lambda z. z) \ \text{of}\ \{ C(z) \rightarrow z \}$ |
|
||||
|
||||
*** Answer
|
||||
See =Assignment.hs=.
|
||||
See =Main.hs=.
|
||||
|
||||
** (1p)
|
||||
Implement multiplication of natural numbers in $\chi$, using the representation of natural numbers given in the $\chi$ specification.
|
||||
@ -98,13 +99,10 @@ Hint: If you want to make use of addition in the implementation of multiplicatio
|
||||
{ Zero() -> Zero()
|
||||
; Succ(n) -> add m (mult n)
|
||||
}
|
||||
#+end_src
|
||||
where we substitute ~add~ for the following:
|
||||
#+begin_src chi
|
||||
\m. rec add = \n. case n of
|
||||
{ Zero() -> m
|
||||
; Succ(n) -> Suc(add n)
|
||||
}
|
||||
[ add <- \m. rec add = \n. case n of
|
||||
{ Zero() -> m
|
||||
; Succ(n) -> Suc(add n)
|
||||
}]
|
||||
#+end_src
|
||||
|
||||
** (2p) [BN]
|
||||
@ -134,4 +132,4 @@ Test your implementation, for instance by testing that addition (defined in the
|
||||
Note that implementing a call-by-value semantics properly in a language like Haskell, which is by default non-strict, can be tricky. However, you will not fail if the only problem with your implementation is that some programs that should fail to terminate instead terminate with a “reasonable” result.
|
||||
|
||||
*** Answer
|
||||
See =Assignment.hs=.
|
||||
See =Main.hs=.
|
||||
@ -12,7 +12,7 @@ library
|
||||
hashable >= 1.4.7.0 && < 1.6,
|
||||
mtl >= 2.2.2 && < 2.4,
|
||||
pretty ^>= 1.1.3.6,
|
||||
QuickCheck ^>= 2.16.0.0,
|
||||
QuickCheck >= 2.16.0.0,
|
||||
transformers >= 0.5.6.2 && < 0.7,
|
||||
unordered-containers ^>= 0.2.20
|
||||
build-tool-depends:
|
||||
@ -28,8 +28,9 @@ library
|
||||
.
|
||||
|
||||
executable interpreter
|
||||
main-is: Assignment.hs
|
||||
main-is: Main.hs
|
||||
hs-source-dirs:
|
||||
interpreter
|
||||
build-depends: base
|
||||
, chi
|
||||
, mtl
|
||||
, unordered-containers
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
|
||||
outputs = { self, nixpkgs, flake-utils }:
|
||||
let
|
||||
ghcVer = "ghc910";
|
||||
ghcVer = "ghc912";
|
||||
makeHaskellOverlay = overlay: final: prev: {
|
||||
haskell = prev.haskell // {
|
||||
packages = prev.haskell.packages // {
|
||||
@ -53,9 +53,6 @@
|
||||
withHoogle = true;
|
||||
buildInputs =
|
||||
(with pkgs; [
|
||||
gnumake
|
||||
jasmin
|
||||
jre_minimal
|
||||
]) ++
|
||||
(with haskellPackages; [
|
||||
haskell-language-server
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
{-# Language LambdaCase, Strict #-}
|
||||
module Assignment where
|
||||
module Main where
|
||||
|
||||
import Chi
|
||||
import Data.Functor ( (<&>) )
|
||||
import Control.Monad.Identity (Identity(runIdentity))
|
||||
import Data.Functor ( (<&>) )
|
||||
import Control.Monad.Identity ( Identity( runIdentity ) )
|
||||
|
||||
-- Task 3
|
||||
subst :: Variable -> Exp -> Exp -> Exp
|
||||
Reference in New Issue
Block a user