Programming Language Assignment HASKELL 1-)Defining a function conc_all that con
ID: 3891167 • Letter: P
Question
Programming Language AssignmentHASKELL
1-)Defining a function conc_all that connects all elements by entering a double list using foldr. Ex.) conc_all [[3,4,5],[8,9,10,11],[1],[2,2,2]] => * [3,4,5,8,9,10,11,1,2,2,2]
2-)Enter a list of strings and define a function showPat that connects all together by inserting newline characters using foldr. Ex.) showPat [“red”,”green”,”blue”,”white”] => * “red greenlue white”
3-)Define function turn which rotates clockwise 90 degrees by inputting a list of character strings using transpose, reverse and turnChar. Ex.) turn [“ ”, “ ” , “ ”] ) =>[“ / / /”, “ / / ” , “ / ” ] Programming Language Assignment
HASKELL
1-)Defining a function conc_all that connects all elements by entering a double list using foldr. Ex.) conc_all [[3,4,5],[8,9,10,11],[1],[2,2,2]] => * [3,4,5,8,9,10,11,1,2,2,2]
2-)Enter a list of strings and define a function showPat that connects all together by inserting newline characters using foldr. Ex.) showPat [“red”,”green”,”blue”,”white”] => * “red greenlue white”
3-)Define function turn which rotates clockwise 90 degrees by inputting a list of character strings using transpose, reverse and turnChar. Ex.) turn [“ ”, “ ” , “ ”] ) =>[“ / / /”, “ / / ” , “ / ” ]
HASKELL
1-)Defining a function conc_all that connects all elements by entering a double list using foldr. Ex.) conc_all [[3,4,5],[8,9,10,11],[1],[2,2,2]] => * [3,4,5,8,9,10,11,1,2,2,2]
2-)Enter a list of strings and define a function showPat that connects all together by inserting newline characters using foldr. Ex.) showPat [“red”,”green”,”blue”,”white”] => * “red greenlue white”
3-)Define function turn which rotates clockwise 90 degrees by inputting a list of character strings using transpose, reverse and turnChar. Ex.) turn [“ ”, “ ” , “ ”] ) =>[“ / / /”, “ / / ” , “ / ” ] HASKELL
1-)Defining a function conc_all that connects all elements by entering a double list using foldr. Ex.) conc_all [[3,4,5],[8,9,10,11],[1],[2,2,2]] => * [3,4,5,8,9,10,11,1,2,2,2]
2-)Enter a list of strings and define a function showPat that connects all together by inserting newline characters using foldr. Ex.) showPat [“red”,”green”,”blue”,”white”] => * “red greenlue white”
3-)Define function turn which rotates clockwise 90 degrees by inputting a list of character strings using transpose, reverse and turnChar. Ex.) turn [“ ”, “ ” , “ ”] ) =>[“ / / /”, “ / / ” , “ / ” ]
Explanation / Answer
Hello there, I am providing solution in Haskell for all three problems given by you:
[1]
conc_all :: [[a]] -> [a]
conc_all listOfList = foldr (++) [] listOfList
[2]
showPat :: [String] -> String
showPat listOfString = foldr (++) ("") l
where
l = (map (++(" ")) (take (n-1) listOfString)) ++ ([(last listOfString)])
n = (length listOfString)
[3]
import Data.List
turn :: [[Char]]->[[Char]]
turn listOfChar = map reverse . transpose $ map (map turnChar) listOfChar
turnChar :: Char -> Char
turnChar c | c== '/' = '\' --SInce to print single '' character use one more '' i.e putStr '\'
| c=='\' = '/'
| c=='|' = '-'
| c== '-' = '|'
| c=='{' = '}'
| c=='}' = '{'
| c=='[' = ']'
| c==']' = '['
| c=='(' = ')'
| c==')' = '('
| c=='<' = '>'
| c=='>' = '<'
---------------------------------------------------------------------------------------------------------------------------------------------
Feel Free to ask queries regarding above solution, I am always here to help you!!
Thank you!!!
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.