CS 430: Lecture 7 - Expressions

Dear students:

A new language is upon us. New languages require us to regress to infancy. The world around is filled with expressions that we can't understand, and we are uncomfortable. Today we embrace that discomfort and start babbling in Haskell by solving some Haskell programming problems in small groups.


To solve these problems, we'll to make use of some of Haskell's builtin functions. These are the ones from the reading plus a few more that you might find useful:


Write a function pairSum that, given a pair of numbers, returns their sum. For example:


Write a function majority that, given a population as an Int, returns the number of people that are needed to count as a majority in that people. For example:


Write a function neck that, given a list, returns its second element. For example:


Write a function slice that, given a list, a starting index, and an ending index, returns the sublist between the given indices. For example:


Write a function frankenstring that, given two strings, returns a string that is the concatenation of the first half of the first string and the second half of the second string. For example:


Write a function transfer that, given a pair of lists, returns a new pair of lists in which the first element of the first list has been prepended on the second list. For example:


Write a function next that accepts two numbers and in an arithmetic sequence and returns the next number. For example:


Write a function quadrant that accepts a Cartesian coordinate pair of numbers. It returns "I", "II", "III", or "IV" to indicate the pairs quadrant. If the pair doesn't lie in a quadrant, it returns "?". For example:


Write a function shy that accepts an Int number of photos that you wish to arrange in a display. It returns the number of photos you need to achieve a fully-packed square. For example:


Write a function mxb that accepts a slope and a y-intercept. It returns the slope-intercept form of the designated line as a string. For example:


Write a function rotateLetter that accepts a Char uppercase letter and an Int offset and returns the letter with the given offset from the given letter. The offset wraps back to A as necessary. For example:


Here's your list of things to do before we meet next:

See you next time.