Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Cse341 23au Public
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cse341-23au
Cse341 23au Public
Commits
669820d7
Commit
669820d7
authored
1 year ago
by
James R. Wilcox
Browse files
Options
Downloads
Patches
Plain Diff
sec02 worksheet
parent
47b46f7e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
section/sec02/sec02.ml
+79
-0
79 additions, 0 deletions
section/sec02/sec02.ml
with
79 additions
and
0 deletions
section/sec02/sec02.ml
0 → 100644
+
79
−
0
View file @
669820d7
(* Section 02 worksheet *)
(** Recursion and non-recursion practice *)
(* Write a function increment_all of type int list -> int list that adds one to
all the elements of the input list. *)
(* YOUR BINDING HERE *)
(* Using these functions from lecture, write another implementation of
sum_of_first_n_ints that is not itself recursive, but only calls other
functions. *)
let
rec
countdown
((
n
:
int
))
=
if
n
=
0
then
[]
else
n
::
countdown
(
n
-
1
)
let
rec
sum
((
l
:
int
list
))
=
if
l
=
[]
then
0
else
List
.
hd
(
l
)
+
sum
(
List
.
tl
(
l
))
(* YOUR BINDING HERE *)
(** Shadowing practice *)
let
a
=
1
let
b
=
2
+
a
let
a
=
"hi"
let
c
=
b
+
1
(* What does this code do? Does it typecheck? What values does each variable have? *)
(** Practice with triples *)
let
fst3
(
x
,_,_
)
=
x
(* gets the first element of a triple *)
let
snd3
(
_
,
x
,_
)
=
x
(* gets the second element of a triple *)
let
thd3
(
_
,_,
x
)
=
x
(* gets the third element of a triple *)
(* Write a function that takes two int triples (i.e., two arguments of type "int
* int * int") and returns whether the third component of the first argument
is equal to the first component of the second argument. *)
(* YOUR BINDING HERE *)
(* Write a function firsts3 that takes an (int * int * int) list and returns an
int list consisting of just the first components of all the triples in the
input list.
Hint: Similar to firsts from lec03.ml
*)
(* YOUR BINDING HERE *)
(** Debugging practice *)
(* The code below has several errors in it so we can try to debug them.
Uncomment it, then fix the errors. *)
(*
let x = 34
y = x + 1
let z = if y then 34 else x < 4
let q = if y > 0 then 0
let w = 0
let let = 34
let v = 4.0 / 2.0
let u = x / w
let 0cse341 = true
*)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment