Question

In: Computer Science

Can someone show me how to write a Haskell function using snd on a list of...

Can someone show me how to write a Haskell function using snd on a list of tuples to create a new list of just the second element in each tuple? Ex. [(‘m’, False), (‘w’, False), (‘n’, True)] would evaluate to [False, False, True].

Solutions

Expert Solution

The program is given below. The comments are provided for the better understanding of the logic.

--The below function will return the 2nd element from a tuple.
--The input passsed to this element is a tuple of (Char, Bool) type
--The returned value is a Bool
--It uses the snd function to return the 2nd element from the tuple.
get2ndElement :: (Char, Bool) -> Bool
get2ndElement x = snd(x)

--The main function goes here
main = do
  --declare the list of tuples with the input.
  let list = [('m', False), ('w', False), ('n', True)]
  --Use map and call the get2ndElement function by passing in the list
  print(map get2ndElement list)

The screenshots of the code and output are provided below.


Related Solutions

can someone explain to me circular, double, linked list? can someone show a program on how...
can someone explain to me circular, double, linked list? can someone show a program on how you would go about using recursive with proper functions and one not using recursive but somethibg simikar! bibary search tree, preorder, post order? good explanation of linked list sorted.
haskell : write a function that reverse the first three element of a list, but not...
haskell : write a function that reverse the first three element of a list, but not the rest. example [1,2,3,4,5,6] == [3,2,1,4,5,6]
Using Haskell, how do you make a function i.e test that will take a list of...
Using Haskell, how do you make a function i.e test that will take a list of integers and add a 5 to the end of that list ex: test [1, 2, 3] will be changed to test [1, 2, 3, 5]
Can someone show me how to calculate theoretical yield using glacial acetic acid as an example?
Can someone show me how to calculate theoretical yield using glacial acetic acid as an example?
Can someone show me how to do a test for lack of fit for the following...
Can someone show me how to do a test for lack of fit for the following data? Please show all work for an up vote. Thanks. y x4 x7 x9 29.5 1.5 4 0 27.9 1.175 3 0 25.9 1.232 3 0 29.9 1.121 3 0 29.9 0.988 3 0 30.9 1.24 3 1 28.9 1.501 3 0 35.9 1.225 3 0 31.5 1.552 3 0 31 0.975 2 0 30.9 1.121 3 0 30 1.02 2 1 36.9 1.664...
Can someone show me the steps of how to solve this? A program needs to access...
Can someone show me the steps of how to solve this? A program needs to access the following pages: 1, 2, 3, 4, 2, 1, 3, 2, 1, 4, 2, 3 There are 3 initially empty frames, how many page faults will there be respectively, if we use First-in-First-out, and Farthest-in-Future page replacement algorithms? A) 7 and 7 B) 7 and 6 --  Correct Answer   C) 6 and 6 D) 6 and 5
Can someone show me step by step how to determine the lattice constants of Graphite?
Can someone show me step by step how to determine the lattice constants of Graphite?
Can someone show me how this answer is 8,080 ? I keep coming up with the...
Can someone show me how this answer is 8,080 ? I keep coming up with the wrong number. Stellar Company has the following sales, variable cost, and fixed cost. If sales increase by $10,000 then their profit increases/decreases by how much? Sales $50,000 Variable Costs $9,600 Fixed Costs $29,000 Answer is 8,080 Calculate the total cost of FC and VC for $50,000. 2) Calculate the increase in VC based on the % increase in Sales. VC/50000 * new sales 3)...
Can someone please show me how to do the work on this please. Question The transactions...
Can someone please show me how to do the work on this please. Question The transactions of the Fury Delivery Service are recorded in the general journal below. Instructions: 1. Post the journal entries to the attached general ledger “T” accounts. 2. Prepare a trial balance on the form provided after the “T” accounts. General Journal Date Account Titles and Explanation Debit Credit 2017 Sept. 1 Cash Common Stock (Stockholders invested cash in business) 25,000 25,000 4 Equipment Cash Notes...
Can someone show me how this is supposed to look in a table format. I want...
Can someone show me how this is supposed to look in a table format. I want to double check that I'm formatting and doing the numbers properly. Thank you! Timber Construction constructs furniture.  They’ve decided they need to layout out their budgets for the first Quarter of 2019 to see if they will make a profit and have cash for a future expansion that will cost $400,000. They always must keep $100,000 minimum in the checking account every month.  (Assume the beginning...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT