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"))))
|
(code =<< code (parse "\\x. x"))))
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
|
\newpage
|
||||||
* Exercises
|
* Exercises
|
||||||
In order to pass this assignment you have to get at least four points.
|
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 \}$ |
|
| ~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
|
*** Answer
|
||||||
See =Assignment.hs=.
|
See =Main.hs=.
|
||||||
|
|
||||||
** (1p)
|
** (1p)
|
||||||
Implement multiplication of natural numbers in $\chi$, using the representation of natural numbers given in the $\chi$ specification.
|
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()
|
{ Zero() -> Zero()
|
||||||
; Succ(n) -> add m (mult n)
|
; Succ(n) -> add m (mult n)
|
||||||
}
|
}
|
||||||
#+end_src
|
[ add <- \m. rec add = \n. case n of
|
||||||
where we substitute ~add~ for the following:
|
|
||||||
#+begin_src chi
|
|
||||||
\m. rec add = \n. case n of
|
|
||||||
{ Zero() -> m
|
{ Zero() -> m
|
||||||
; Succ(n) -> Suc(add n)
|
; Succ(n) -> Suc(add n)
|
||||||
}
|
}]
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
** (2p) [BN]
|
** (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.
|
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
|
*** Answer
|
||||||
See =Assignment.hs=.
|
See =Main.hs=.
|
||||||
@ -12,7 +12,7 @@ library
|
|||||||
hashable >= 1.4.7.0 && < 1.6,
|
hashable >= 1.4.7.0 && < 1.6,
|
||||||
mtl >= 2.2.2 && < 2.4,
|
mtl >= 2.2.2 && < 2.4,
|
||||||
pretty ^>= 1.1.3.6,
|
pretty ^>= 1.1.3.6,
|
||||||
QuickCheck ^>= 2.16.0.0,
|
QuickCheck >= 2.16.0.0,
|
||||||
transformers >= 0.5.6.2 && < 0.7,
|
transformers >= 0.5.6.2 && < 0.7,
|
||||||
unordered-containers ^>= 0.2.20
|
unordered-containers ^>= 0.2.20
|
||||||
build-tool-depends:
|
build-tool-depends:
|
||||||
@ -28,8 +28,9 @@ library
|
|||||||
.
|
.
|
||||||
|
|
||||||
executable interpreter
|
executable interpreter
|
||||||
main-is: Assignment.hs
|
main-is: Main.hs
|
||||||
|
hs-source-dirs:
|
||||||
|
interpreter
|
||||||
build-depends: base
|
build-depends: base
|
||||||
, chi
|
, chi
|
||||||
, mtl
|
, mtl
|
||||||
, unordered-containers
|
|
||||||
|
|||||||
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
outputs = { self, nixpkgs, flake-utils }:
|
outputs = { self, nixpkgs, flake-utils }:
|
||||||
let
|
let
|
||||||
ghcVer = "ghc910";
|
ghcVer = "ghc912";
|
||||||
makeHaskellOverlay = overlay: final: prev: {
|
makeHaskellOverlay = overlay: final: prev: {
|
||||||
haskell = prev.haskell // {
|
haskell = prev.haskell // {
|
||||||
packages = prev.haskell.packages // {
|
packages = prev.haskell.packages // {
|
||||||
@ -53,9 +53,6 @@
|
|||||||
withHoogle = true;
|
withHoogle = true;
|
||||||
buildInputs =
|
buildInputs =
|
||||||
(with pkgs; [
|
(with pkgs; [
|
||||||
gnumake
|
|
||||||
jasmin
|
|
||||||
jre_minimal
|
|
||||||
]) ++
|
]) ++
|
||||||
(with haskellPackages; [
|
(with haskellPackages; [
|
||||||
haskell-language-server
|
haskell-language-server
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
{-# Language LambdaCase, Strict #-}
|
{-# Language LambdaCase, Strict #-}
|
||||||
module Assignment where
|
module Main where
|
||||||
|
|
||||||
import Chi
|
import Chi
|
||||||
import Data.Functor ( (<&>) )
|
import Data.Functor ( (<&>) )
|
||||||
Reference in New Issue
Block a user