ECS 140A Homework Assignment 3
For each of the following problems, you are to provide two
solutions:
one using the pattern-matching techniques we
Copyright By PowCoder代写 加微信 powcoder
discussed in class Thursday, and one not using those pattern-
matching techniques (i.e.,
the ones we used in class before we
talked about pattern-matching over lists).
For example, the two
solutions for myappend might look like:
without pattern matching
myappend listl list2
== [1 = list2
(head listl): (myappend (tail listl) list2)
with pattern matching
myappend pm [1 list2
myappend pm (x:xs) list2
= x: (myappend pm xs list2)
Note that I have ended the name of the pattern-matching solution
Please do the
same for all the pattern-matching
solutions that you submit for this assignment.
Tistmplemertothe function bal ow, y°k may use on rather fnl lowing
list operations
(Note that there are pattern matching equivalents for most of
Do not resort to just qiving a new name to an existing
Haskell function that already does what we want your function to
So, for example
myappend inlistl inlist2
= inlist1 ++ inlist2
wouldn’t get you any points.
more times than is necessary.
Also, do not traverse any list
Please make sure you name your functions with the names provided
below (with and without the
pm suffix).
Also, include type
declarations with your functions.
It will be good practice.
Submit your solutions as a single file named
Grading will be on a 3-point scale for each solution (7 problems
solutions per problem x 3 points maximum per solution
points maximum)
And now, here are your homework problems:
1) myremoveduplicates
myremoveduplicates
myremoveduplicates [3,2,1,3, 2,2,1,1] => [3,2,1]
2) myintersection
For this function, the order of the elements in the list
returned by the function doesn’t matter.
Also, if the arguments
to the function have duplicate elements in the list, then the
result of the intersection is unspecified.
myintersection
myintersection [3,4,2,1] [5,4,1, 6,2] => [4,2,1]
myintersection (] [1,2,3]
myintersection
3) mynthtail
mynthtail 0
mynthtail 2
mynthtail 2 (1
mynthtail 4 [1,
mylast (1,
3, 41 => [41
5) myreverse
There’s a simple but inefficient solution to this problem,
much more efficient solution.
For full credit, provide the more
efficient solution
myreverse [1, 2,
myreverse (1
6) myreplaceall
myreplaceall 3 7 [7,0,7,1,7,2,71 => [3,0,3,1, 3,2,3]
myreplaceall
myreplaceall
7) myordered
myordered [l
myordered [1]
myordered [1,2]
myordered [1,1]
myordered [2,1]
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com