Principles 2024 – 2025 CSCI-2041
Final Exam 1 Review Questions with
Verified Solutions | 100% Pass
Guaranteed | Graded A+ |
Administrator
[COMPANY NAME] [Company address]
, # Final Exam Practice Questions
*CSci 2041: Advanced Programming Principles, Fall 2015*
These are some examples of questions similar to those that will
appear on the final exam. Since the final is comprehensive, you
should start by taking a look at the example questions for
[midterm 1](midterm1-practice.md) and [midterm 2](midterm2-practice.md).
##1. Values and types
Since defining and using data types as a method of structuring your
programs is a central concept in functional programming and OCaml, you
should be able to infer the types of OCaml expressions, and identify
type errors when they occur. For each of the following expressions
you should be able to:
- Identify whether the expression contains a type error, or if it is
well-typed, what its type is.
- If the expression contains a type error, you should be able to
explain the type error; if it is well-typed you should be able to
give the result of evaluating the expression. Since OCaml has
first-class functions, some expressions might evaluate to functional
values, in which case you should explain briefly what the function
computes.
The midterm 1 examples cover much of the basics, but here are some
examples focusing on some of the OCaml features we've learned since
then:
```
open Lwt
let t = Lwt.return 17 >>= fun i -> Lwt.return string_of_int i
>>= fun s -> Lwt_io.printl s
```
```
open Lwt
let t = Lwt_unix.sleep 1.5 >>= fun () -> print_endline "Great nap!"
```
```
let a = ref [] in
a := 32::!a ; a := ["stringlist!"]
```
```
let a = ref 14 in
let f r = begin r := !r+1 end in
f a; f a
```
```
type 'a mlist = Nil or L of 'a mcell
and 'a mcell = { hd: 'a ; mutable tl : 'a mlist}
let update_hd v lst = match lst with
| Nil -> L {hd=v, tl=Nil}
| L c -> c.hd <- v
```
```
let rec defer f x = lazy(f x)
This study source was downloaded by 100000873818132 from CourseHero.com on 10-18-2024 17:15:16 GMT -05:00
https://www.coursehero.com/file/13271011/final-exam-practicemd/