Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
CS 306: Automata theory and programming languages
Fall Term, 2015
Lab 1
Introduction to Haskell
The purpose of this lab is to have you practice using Haskell. I don’t have a highly structured exercise in
mind. Instead, practice by working on these functions:
1. Write a function myOdd that returns whether its argument is odd. To perform integer division and take
remainders the functions are div and mod, but these need to be used as functions:
div 4 3 -- equivalent to 4 / 3 in Java
mod 4 3 -- 4 % 3 in Java
2. A function contains that takes a value and a list, returning whether that value is contained in the list.
3. A function numOccurences that takes a value and a list, returning the number of times that value
appears in the list.
4. A function equal that takes two lists and returns whether they have the same contents (order matters).
5. A function addOne that takes a list of numbers and returns a list where those numbers have all been
increased by 1. (So that addOne [1,2,3] returns [2,3,4].)
6. A function justOdds that takes a list of integers and returns a list containing only its odd elements.
7. A function removeAll that takes a value and a list, returning a list identical to the given one except
that all occurrences of the value have been removed.
8. A function removeFirst that is the same as removeAll except that only the first occurrence is removed.
9. A function everyOther that takes a list and returns another list containing every other element in the
original. In other words, it contains the first element from the original list, the third element, the fifth
element, and so on. Make sure your function works for both even-length and odd-length lists.
10. A function get that takes an integer and a list, returning the value at that index in the list. Assume
indices start at 0. If the index is too large, have the function throw an exception. To do this, invoke
error "index out of bounds".
11. A function indexOf that takes a value and a list, returning the index of the first occurrence of that
value in the list. Assume that indices start with 0. Return -1 if the given value does not occur in the
list.
12. A function removeLast that is the same as the previous two removal functions except only the last
occurrence is removed.
If you have more time, think of some other functions you might want to perform and implement them. I
particularly encourage you to write functions for lists or strings and practice your use of recursion.