Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Haskell.
Write a Haskell function evenLength :: [a] -> Bool and the corresponding Prolog predicate evenLength, which returns (or resolves to) true when the single list argument passed to it has even length.
Note: that these must be written from scratch, so no previously defined functions may be used, e.g., the Prelude length function (or the Prolog length predicate) may not be used — your solutions will be recursive. You may, of course define auxiliary helper functions (which also must be written from scratch), e.g., the appropriate oddLength :: [a] -> Bool might be useful in Haskell, and similarly, an oddLength predicate in Prolog.
The idea is that in Haskell, e.g., evenLength [1,2,3,4] would return True, and evenLength "hey" would return False, while in Prolog, e.g., the query evenLength([1,2,3,4]). would resolve to true, and the query evenLength([a,b,c]). would resolve to false.
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 7 steps with 4 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.Similar questions
- In Haskell Language write matchEmpty, which determines whether the language for a regular-- expression includes the empty string.matchEmpty :: RE symbol -> BoolmatchEmpty = ?-- Note that the type signature does not restrict symbol to types with-- equality testing, so we cannot use match or match' to check whether the-- empty string is allowed.---- matchEmpty r = match r [] -- type error---- Similarly, we cannot use generate' and check whether the first string-- it provides is the empty string.---- Finally, while generate has the proper type, we cannot use it to write a-- function that always terminates, as we cannot conclude that the empty-- string is not present until we have examined every string.---- *HW3> matchEmpty (getRE "e")-- True-- *HW3> matchEmpty (getRE "abc*")-- False-- *HW3> matchEmpty (getRE "a*")-- True-- *HW3> matchEmpty (getRE "0")-- False-- *HW3> matchEmpty (getRE "0*")-- True NOTE: Above are a few examples of what the output will look like. All…arrow_forwardPlease can someone explain each line alongside each symbol of the expression Please please give a detailed explanation I will upvote it , explicitly pattern matchingarrow_forwardDevelop an algorithm and write a C++ program that counts the letter occurrence in the string; make sure you use call by reference to the array of a class with letter and count as private member attributes when return from parse function. For the class member methods, provide the public accessor and modifier as well as print functions for the private member attributes. Write a test program that reads a C-string and displays the number of letters [a-z] and number of numbers [0-9] in the string. In addition to that, you need to output the histogram of the letter and count array. Here is a sample run of the program: <Output> Enter a string: 2023 is coming The number of letters in 2023 is coming is 8 The number of numbers in 2023 is coming is 4 ---- Histogram ---- Char Count 0 1 2 2 3 1 c 1 g 1 i 2 m 1 n 1 /* not a completed output */ <End Output>arrow_forward
- Program in Carrow_forwardWrite a small C++ program that defines a recursive function GCD based on the model of the Lisp function (defun gcd (n m)"Returns the gcd of two numbers" (let ((dividend n) (divisor m) (remainder 1)) (while (/= remainder 0) (setq remainder (mod dividend divisor)) (setq dividend divisor) (setq divisor remainder)) dividend)) In the main function, write a loop (while or do) that repeats the following actions: ask the user to enter two numbers, compute their GCD and output it, until the user enters 0 for one of the numbers.arrow_forwardModify the function joinLine so that it right align the line to lengthlineLen by adding the appropriate number of space at the beginning ofthe line. (in Haskell) code: joinLine :: Line -> String joinLine [] = [] joinLine (w:ws) = w ++ " " ++ (joinLine ws)arrow_forward
- Develop a system/application in Prolog that will allow grader to: load a set of student’s grades (see samples from the Table C below) query student’s final letter grade (A, B, C, etc.) by a given student’s name. query student(s) whose grade matches to the input letter grade (e.g., A). For example, show student(s) whose final letter grade is A. There are 3 types of grades for each student—HWs, Exams, and Project, with a weight of 20%, 40% and 40%, respectively, to the 100-point final. Table A and B show how the final grades (in points and letter) are computed. Table C shows samples of students’ grades. You will define the execution instructions to answer the following questions so that grader can test out your application in Prolog: how to load your source code to Prolog runtime/compiler how to load students’ grades to Prolog runtime/compiler how to query student’s letter grade how to query student(s) whose letter grade matches to an input letter grade Please DO NOT hard code any…arrow_forwardIn Kotlin, Write a recursive function called myZip, with an expression body. MyZip takes two Lists and returns a List of Pairs in which each value may be any type (I suggest your start by thinking out how to represent this data type). The pairs consist of corresponding elements in the two lists (the first element of the first list and the first element of the second list, etc). The base case should be that either (or both) of the original lists has length 1, so that, if the lists have different length, the zipping stops when the first list runs out of values.arrow_forwardHaskellarrow_forward
- I need the answer as soon as possiblearrow_forwardI need this function to be defined using Haskell language. Hailstone sequences are produced by repeatedly applying the following mapping to numbers: an even number n maps to n/2 and an odd number m maps to 3m+1.The function hailmap applies this transformation to a single integer.hailmap :: Integer -> Integerhailmap n = undefined Note: when the function is called using an integer the answer will be given based on the number being odd or even. -- ghci> hailmap 7-- 22-- ghci> hailmap 8-- 4 Note: Use div rather than / for division, to avoid the need for conversion between numeric types.-- ghci> 15 `div` 2-- 7arrow_forwardIn c++, Thanks!!! Write the simplest program that will demonstrate iteration vs recursion using the following guidelines - Write two primary helper functions - one iterative (IsArrayPrimeIter) and one recursive (IsArrayPrimeRecur) - each of which Take an array and its size as input params and return a bool such that 'true' ==> array and all elements are prime, 'false' ==> at least one element in array is not prime, so array is not prime. Print out a message "Entering <function_name>" as the first statement of each function. Perform the code to test whether every element of the array is a Prime number. Print out a message "Leaving <function_name>" as the last statement before returning from the function. Remember - there will be nested loops for the iterative function and there can be no loops at all in the recursive function. You will need to define one other helper function (IsPrimeRecur) for the recursion which should also not contain any loops to make it a…arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY