Sign in to follow this  
Larloch

Haskell Help

Recommended Posts

Hey guys

I am a Comp Sci student and I am in desperate need of someone that can handle haskell well to help me with some tasks. The tasks should be trivial.
Pm for more info please if someone wants to help me out.
Thank you in advance for considering :P:P

Share this post


Link to post
Share on other sites
module Cw2010 where
import Char
import Hugs.Prelude


type Canvas = [String]

painting :: Int -> Canvas
painting 1 = ["+---+---+---+---+---+",
"| | | | | |",
"+---+---+---+---+---+",
"| | | | | |",
"+---+---+---+---+---+",
"| | | | | |",
"+---+---+---+---+---+",
"| | | | | |",
"+---+---+---+---+---+",
"| | | | | |",
"+---+---+---+---+---+",
"| | | | | |",
"+---+---+---+---+---+",
"| | | | | |",
"+---+---+---+---+---+",
"| | | | | |",
"+---+---+---+---+---+"]

painting 2 = ["+---+---+---+---+---+",
"| a | n | e | x | a |",
"+---+---+---+---+---+",
"| m | p | l | e | t |",
"+---+---+---+---+---+",
"| e | x | t | i | s |",
"+---+---+---+---+---+",
"| s | h | o | w | n |",
"+---+---+---+---+---+"]

painting 3 = ["+---+---+---+---+---+---+---+",
"| A | n | o | t | h | e | r |",
"+---+---+---+---+---+---+---+",
"| | t | e | s | t | ! | |",
"+---+---+---+---+---+---+---+"]

painting 4 = ["+---+---+---+---+---+---+---+",
"| Y | e | t | | | | |",
"+---+---+---+---+---+---+---+",
"| A | n | o | t | h | e | r |",
"+---+---+---+---+---+---+---+",
"| t | e | s | t | ! | |",
"+---+---+---+---+---+---+"]

(1) Three functions should be defined here.

– Define showPic :: Canvas -> IO () for displaying pictures on the
terminal. Examples:
Cw2010> showPic (painting 2)
+---+---+---+---+---+
| a | n | e | x | a |
+---+---+---+---+---+
| m | p | l | e | t |
+---+---+---+---+---+
| e | x | t | i | s |
+---+---+---+---+---+
| s | h | o | w | n |
+---+---+---+---+---+
Cw2010> showPic (painting 3)
+---+---+---+---+---+---+---+
| A | n | o | t | h | e | r |
+---+---+---+---+---+---+---+
| | t | e | s | t | ! | |
+---+---+---+---+---+---+---+
– Furthermore, define sizeRaw :: Canvas -> (Int, Int) for finding
out the size of a raw picture as demonstrated here.
Cw2010> sizeRaw ["anexa","mplet","extis","shown"]
(5,4)
– Finally, define isPic :: Canvas -> Bool for checking a particular
necessary condition which items of type Canvas must satisfy (full or
raw). The condition you should check for is whether all the ‘rows’ of
the input have the same length. (It may be assumed that the input
of isPic is of type Canvas.) Examples:
Cw2010> isPic (painting 3)
True
Cw2010> isPic (painting 4)
False
Suggestion. I found it useful in my implementation to define and use
here the auxiliary function isEqual :: [Int] -> Bool; example:
Cw2008> isEqual [8,8,8,8]
True
Cw2008> isEqual [8,8,4,8]
False
You may wish to define and use isEqual in your implementation of
isPic too.
The maximum achievable number of marks for each task is 7, marking advice
making a total of 21.
(2) Define sizeFull :: Canvas -> (Int, Int) for measuring the size of a
full picture. You may assume that the input of sizeFull is of the correct
type Canvas. (Your function sizeFull will look similar to sizeRaw from
(1) but it will be somewhat more complicated!) Example:
Cw2010> sizeFull (painting 3)
(7,2)
The maximum achievable number of marks for this task is 7. marking advice
(3) Two functions should be defined here.
– Define row :: Int -> Canvas -> String for returning a specific
row of a full picture. Example:
Cw2010> row 3 (painting 2)
"| e | x | t | i | s |"
– Define cell :: Int -> Int -> Canvas -> Char for returning a spe-
cific pixel of a full picture. Example:
Cw2010> cell 2 3 (painting 2)
’x’
You should use the built-in operator !! in both of the your definitions.
The definition of cell ideally uses the function row.
The maximum achievable number of marks for each task is 7, marking advice
making a total of 14.
(4) Define emptyFull :: Int -> Int -> Canvas for returning a full empty
picture of a specified size. Illustration:
Cw2010> showPic (emptyFull 4 3)
+---+---+---+---+
| | | | |
+---+---+---+---+
| | | | |
+---+---+---+---+
| | | | |
+---+---+---+---+
Cw2010> emptyFull 4 3
["+---+---+---+---+","| | | | |","+---+---+---+---+","| | | | |",
"+---+---+---+---+","| | | | |","+---+---+---+---+"]
Note. I have introduced here the auxiliary functions
again :: Int -> a -> [a]
emptyline :: Int -> String
separatorH :: Int -> String
to perform tasks as demonstrated below. An example of how they behave
is as follows.
Cw2010> again 4 "text"
["text","text","text","text"]
Cw2010> emptyline 4
"| | | | |"
Cw2010> separatorH 6
"+---+---+---+---+---+---+"
You may wish to define these too for your implementation of emptyFull.
The maximum achievable number of marks for completing this marking advice
task is 14.
(5) Write a function toRaw :: Canvas -> Canvas for converting a full pic-
ture to its raw equivalent. You may assume that the input of toRaw is of
the correct type Canvas. Example:
Cw2010> showPic (toRaw (painting 2))
anexa
mplet
extis
shown
Note. I have introduced here the auxiliary functions
removeHSep :: Canvas -> Canvas
removeV :: String -> String
removeVSep :: [String] -> [String]
An example of how they behave is as follows.
Cw2010> removeHSep (painting 2)
["| a | n | e | x | a |","| m | p | l | e | t |","| e | x | t | i | s |","| s | h | o | w | n |"]
Cw2010> removeV "| a | n | e | x | a |"
"anexa"
Cw2010> removeVSep ["| a | n | e | x | a |","| m | p | l | e | t |","| e | x | t | i | s |","| s | h | o | w | n |"]
["anexa","mplet","extis","shown"]
(Hint. I have used recursion to define the first two of the above axiliary
functions. removeVSep was defined by mapping removeV.)
You may wish to define these three functions too for your implementation
of toRaw.
The maximum achievable number of marks for completing this marking advice
task is 14.
(6) Write a function toFull :: Canvas -> Canvas for converting a raw pic-
ture to its full equivalent. Illustration:
Cw2010> toFull ["some text","line 2 ","line 3 "]
["+---+---+---+---+---+---+---+---+---+",
"| s | o | m | e | | t | e | x | t |",
"+---+---+---+---+---+---+---+---+---+",
"| l | i | n | e | | 2 | | | |",
"+---+---+---+---+---+---+---+---+---+",
"| l | i | n | e | | 3 | | | |",
"+---+---+---+---+---+---+---+---+---+"]
Cw2010> showPic (toFull ["some text","line 2 ","line 3 "])
+---+---+---+---+---+---+---+---+---+
| s | o | m | e | | t | e | x | t |
+---+---+---+---+---+---+---+---+---+
| l | i | n | e | | 2 | | | |
+---+---+---+---+---+---+---+---+---+
| l | i | n | e | | 3 | | | |
+---+---+---+---+---+---+---+---+---+
Note. I have introduced here the auxiliary functions
insertV :: String -> String
insertVSep :: Canvas -> Canvas
insertHSep :: String -> Canvas -> Canvas
An example of how they behave is as follows.
Cw2010> insertV "some text here"
"| s | o | m | e | | t | e | x | t | | h | e | r | e |"
Cw2010> insertVSep ["text1","text2"]
["| t | e | x | t | 1 |","| t | e | x | t | 2 |"]
Cw2010> insertHSep "+---+---+---+---+---+" ["| t | e | x | t | 1 |","| t | e | x | t | 2 |"]
["+---+---+---+---+---+","| t | e | x | t | 1 |","+---+---+---+---+---+","| t | e | x | t | 2 |","+---+---+---+---+---+"]
The maximum achievable number of marks for this task is 5. marking advice
(7) Write a function
changeRaw :: Char -> Int -> Int -> Canvas -> Canvas
for changing a specific location (pixel) in a raw image to a specified char-
acter. Examples:
Cw2010> showPic ["mouse a", "dog b", "cat c", "tiger d"]
mouse a
dog b
cat c
tiger d
Cw2010> changeRaw ’u’ 2 3 ["mouse a", "dog b", "cat c", "tiger d"]
["mouse a","dog b","cut c","tiger d"]
Cw2010> showPic $$
mouse a
dog b
cut c
tiger d
Cw2010> showPic (toFull (changeRaw ’*’ 4 3 (toRaw (painting 2))))
+---+---+---+---+---+
| a | n | e | x | a |
+---+---+---+---+---+
| m | p | l | e | t |
+---+---+---+---+---+
| e | x | t | * | s |
+---+---+---+---+---+
| s | h | o | w | n |
+---+---+---+---+---+
Hints.
Ê In my implementation of changeRaw I have introduced the auxiliary
function
changeStr :: Int -> Char -> String -> String
which allows me to redefine a particular position of a String. Ex-
amples:
Cw2010> changeStr 2 ’i’ "ball"
"bill"
Cw2010> changeStr 1 ’t’ "ball"
"tall"
Cw2010> changeStr 4 ’s’ (changeStr 3 ’t’ "ball")
"bats"
Define changeStr and use it in your definition of changeRaw too.
Ë The built-in functions used in defining changeStr and changeRaw
are take, drop, ++ and !!.
The maximum achievable number of marks for this task is 5. marking advice
(8) Define a function
drawHRaw :: Char -> Int -> Int -> Int -> Canvas -> Canvas
for drawing a horizontal straight line onto a raw picture. Example:
Cw2010> showPic (drawHRaw ’*’ 7 2 3 ["first line","second line","third line","fourth line","fifth line"])
first line
second***ne
third line
fourth line
fifth line
As seen here, the arguments of drawHRaw are in turn,
– The character to be used.
– The column of the start of the straight line.
– The row of the start of the straight line.
– The length of the straight line.
– The raw form of the image to be drawn upon.
Horizontal lines will be drawn from left to right.
Hint. Define drawHRaw by recursion and use there changeRaw from (7) as
an auxiliary function.
The maximum achievable number of marks for this task is 7. marking advice
(9) Define a function
drawVRaw :: Char -> Int -> Int -> Int -> Canvas -> Canvas
for drawing a vertical straight line onto a raw picture. Example:
Cw2010> showPic (drawVRaw ’*’ 7 2 3 ["first line","second line","third line","fourth line","fifth line"])
first line
second*line
third *line
fourth*line
fifth line
As seen here, the arguments of drawVRaw are in turn,
– The character to be used.
– The column of the start of the straight line.
– The row of the start of the straight line.
– The length of the straight line.
– The raw form of the image to be drawn upon.
Vertical lines will be drawn from left to right.
Hint. Define drawVRaw by recursion and use there changeRaw from (7) as
an auxiliary function.
The maximum achievable number of marks for this task is 7. marking advice
(10) Define a function
drawRRaw :: Char -> Int -> Canvas -> Canvas
for drawing a rectangle around the edge of a raw picture. Its arguments
are in turn,
– The character to be used.
– The width of the edge strip around the rectangle (see illustration
below).
– The picture onto which we draw.
Two examples are shown on page 12.
Hint. In your definition of drawRRaw use the functions drawHRaw and
drawVRaw from (8) and (9) respectively.
Note. There are of course numerous other ways of building interesting
new functions using drawHRaw and drawVRaw. For example, lines could be
drawn in a diagonal direction (descending or ascending or with a specified
slope). You may wish to define new functions along these lines. Include
your work in your submission even though anything beyond the present
specifications won’t attract marks.
The max. achievable number of marks for this task is 6. marking advice
Example applications of drawRRaw (Task 10)
Cw2010> showPic (toFull (drawRRaw ’*’ 2 (toRaw (emptyFull 13 7))))
+---+---+---+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+---+---+---+
| | | * | * | * | * | * | * | * | * | * | | |
+---+---+---+---+---+---+---+---+---+---+---+---+---+
| | | * | | | | | | | | * | | |
+---+---+---+---+---+---+---+---+---+---+---+---+---+
| | | * | * | * | * | * | * | * | * | * | | |
+---+---+---+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+---+---+---+
Cw2010> showPic (toFull (drawRRaw ’c’ 2 (drawRRaw ’b’ 1 (drawRRaw ’a’ 0 (toRaw (emptyFull 13 7))))))
+---+---+---+---+---+---+---+---+---+---+---+---+---+
| a | a | a | a | a | a | a | a | a | a | a | a | a |
+---+---+---+---+---+---+---+---+---+---+---+---+---+
| a | b | b | b | b | b | b | b | b | b | b | b | a |
+---+---+---+---+---+---+---+---+---+---+---+---+---+
| a | b | c | c | c | c | c | c | c | c | c | b | a |
+---+---+---+---+---+---+---+---+---+---+---+---+---+
| a | b | c | | | | | | | | c | b | a |
+---+---+---+---+---+---+---+---+---+---+---+---+---+
| a | b | c | c | c | c | c | c | c | c | c | b | a |
+---+---+---+---+---+---+---+---+---+---+---+---+---+
| a | b | b | b | b | b | b | b | b | b | b | b | a |
+---+---+---+---+---+---+---+---+---+---+---+---+---+
| a | a | a | a | a | a | a | a | a | a | a | a | a |
+---+---+---+---+---+---+---+---+---+---+---+---+---+

This is it allthough i wouldn't mind paying 20$an hour for someone to e actually do it and axplain it to me :)

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this