Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. A)write a function in HASKELL to reverse a string(or list) without using the

ID: 3831012 • Letter: 1

Question

1. A)write a function in HASKELL to reverse a string(or list) without using the built in reverse function.
B)write a function in Haskell to multiply each element in a list by three:
C)given a Haskell type declaration of myFunc : : Num a => [a] --> a what is the data type of the function's parameter? Show an example valid input:
What is the data type of the functions return value? Show an example valid return value: 1. A)write a function in HASKELL to reverse a string(or list) without using the built in reverse function.
B)write a function in Haskell to multiply each element in a list by three:
C)given a Haskell type declaration of myFunc : : Num a => [a] --> a what is the data type of the function's parameter? Show an example valid input:
What is the data type of the functions return value? Show an example valid return value: A)write a function in HASKELL to reverse a string(or list) without using the built in reverse function.
B)write a function in Haskell to multiply each element in a list by three:
C)given a Haskell type declaration of myFunc : : Num a => [a] --> a what is the data type of the function's parameter? Show an example valid input:
What is the data type of the functions return value? Show an example valid return value:

Explanation / Answer

write a function in HASKELL to reverse a string(or list) without using the built in reverse function:

rev :: [a] -> [a]

rev list = sl list[]

sl :: [a] -> [a] -> [a]

sl list1 newList

| null list1 = newList

| otherwise = sl (tail list1) ((head list1) : newList)

write a function in Haskell to multiply each element in a list by three:

given a Haskell type declaration of myFunc : : Num a => [a] --> a what is the data type of the function's parameter? Show an example valid input:

Num is a numeric type class. Its instances can act like numbers.

Let’s examine the type of a number:

ghci> :t 20

20 :: (Num t) => t

It appears that whole numbers are also polymorphic constants. They can act like any type that’s an instance of the Num type class (Int, Integer, Float, or Double):

ghci> 20 :: Int 20

ghci> 20 :: Integer 20

ghci> 20 :: Float 20.0

ghci> 20 :: Double 20.0

For example, we can examine the type of the * operator:

ghci> :t (*) (*) :: (Num a) => a -> a -> a

This shows that * accepts two numbers and returns a number of the same type. Because of this type constraint, (5 :: Int) * (6 :: Integer) will result in a type error, while 5 * (6 :: Integer) will work just fine. 5 can act like either an Integer or an Int, but not both at the same time.