Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Basic Function Please define the following functions in Haskell. TI 11 (a) Function sumSquares that, given a nonnegative integer n, returns 2 Type: (Eq

image text in transcribed
1. Basic Function Please define the following functions in Haskell. TI 11 (a) Function sumSquares that, given a nonnegative integer n, returns 2 Type: (Eq p, Num p) => p -> P Examples: sumSquares 4 = 30 sumSquares 5 - 55 (b) Function listDup that takes a pair, which consists of an element, e, of any type, and a non-negative number 1, as input and returns a list with n copies of e. Type: (Eq b, Num b) => (a, b) => [a] Examples: listDup ("moo", 4) = ["moo", "moo", "moo", "moo"] listDup (1,2) [1,1] listDup (listDup ("cow", 2), 2) - [{"cow", "Cow"],["cow", "Cow"]] 2. Recursion on lists Please define the following functions in Haskell. (a) Function getEvens takes a list of integers as input and returns a list by keeping only the elements that are even in their original order. Type: Integral a => [a] -> [a] Examples: getEvens (1,2,3,4,8,5,2] [2,4,8,2] (b) Function incBy takes a list of integers I and an integer n as input and returns a list by increasing every element in l by n. Type: Num a => a => [a] -> [a] Examples: incBy 5 [2,4,7) [7,9,12]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Visual C# And Databases

Authors: Philip Conrod, Lou Tylee

16th Edition

1951077083, 978-1951077082

More Books

Students also viewed these Databases questions

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago