Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Haskell problems

Name: Anonymous 2008-11-27 2:42

Hello /prog/
Please post the solutions to these problems by Friday.
Thanks

Define a function commaSeparate :: [String] -> String that takes a list of strings and returns a single string that contains the given strings in the order given, separated by ", ". For example,
commaSeparate [] = ""
commaSeparate ["a", "b"] = "a, b"
commaSeparate ["Monday", "Tuesday", "Wednesday", "Thurssday" ]
= "Monday, Tuesday, Wednesday, Thursday"


Write a function compose :: [(a -> a)] -> (a -> a) that takes a list of functions, and returns a function which is their composition. For example:
compose [] [1, 2, 3] = [1, 2, 3]
compose [(\ x -> x + 1), (\ x -> x + 2)] 4 = 7
compose [tail, tail, tail] [1, 2, 3, 4, 5] = [4, 5]
compose [(\ x -> 3 : x), (\ y -> 4 : y)] [] = 3 : (4 : [])
Hint: note that compose [] is the identity function.


Write and test the definition of a (polymorphic) Haskell function 'center' that takes three arguments, a list arg1 of type [a], a width arg2 of type Int, and a fill item arg3 of type a, and returns a list of length arg2 of type [a] containing list arg1 centered within fill items (i.e., the difference between the number of items preceding arg1 and those following arg1 is at most 1). For instance, center "abcd" 7 '-' could yield "--abcd-" or "-abcd--" (as you choose).


The Haskell function  ‘scanSum’ adds the items in a list and returns a list of the running totals. So scanSum [2,3,4,5] returns [2,5,9,14]. Is there any difference between "scanSum (takeInt 10 [1..])" and "takeInt 10 (scanSum [1..])"? Explain your answer.


Write and test the definition of a Haskell function 'largest', which finds the largest element of a list, but is implemented using higher-order functions and/or operator sections as appropriate.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List