Consider a data type for logical expressions data Expr = Var String Or [Expr] And [Expr]...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Consider a data type for logical expressions data Expr = Var String Or [Expr] And [Expr] -- A variable with given name | | | Not Expr deriving (Eq, Show) Write a function collect :: Expr -> ([String], Int), which col- lects a list of unique variable names in an expression, and the total number of times a "Not" appears. You may write helper functions if you wish. For example > expr = And [Var "a", Or [Var "a", Var "b"], Not (Var "c")] > collect expr ( ["a", "b", "c"], 1) Consider a data type for logical expressions data Expr = Var String Or [Expr] And [Expr] -- A variable with given name | | | Not Expr deriving (Eq, Show) Write a function collect :: Expr -> ([String], Int), which col- lects a list of unique variable names in an expression, and the total number of times a "Not" appears. You may write helper functions if you wish. For example > expr = And [Var "a", Or [Var "a", Var "b"], Not (Var "c")] > collect expr ( ["a", "b", "c"], 1)
Expert Answer:
Answer rating: 100% (QA)
To implement the collect function for the Expr data type you can use a recursive approach to travers... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
Describe the business of Costco Wholesale Corporation.Your description must include the following topics (at least the top 3): 1. Which industry? 2. When did Costco become a public company? 3. Type...
-
Using Python, In this assignment, we will analyze the HURDAT2 dataset for Atlantic hurricane data from 1851 through 2017. This dataset is provided by the National Hurricane Center and is documented...
-
Identify each process as endothermic or exothermic and indicate the sign of H. (a) Sweat evaporating from skin (b) Water freezing in a freezer (c) Wood burning in a fire
-
Tedesco Company changed depreciation methods in 2019 from double-declining-balance to straight-line. Depreciation prior to 2019 under double-declining-balance was $90,000, whereas straight-line...
-
You are performing a financial audit of the general ledger accounts of Preston Manufacturing. As transactions are processed summary journal entries are added to the general ledger file at the end of...
-
Describe the various errors that can occur in the administration of medications.
-
Fill in the missing blocks for the ANOVA summary table on net profits and market value used with regression analysis. a. What does the F tell you? (Alpha= .05) b. What is the t value? Explain...
-
Consider a version of Solow's Model: Y = AKL-a SY K+1 K++8Kt Lt = Lo(1+n)t 1 a) Rewrite the production function and the equation of capital accummulation using variables normalized by the units of...
-
The October 31, 2017, bank statement of Jazzera Distributors has just arrived. To prepare Jazzera Distributors' bank reconciliation, you gather the following data: a. The October 31 bank balance is...
-
Instructions Notice that variables have been declared for you. Write input statements to retrieve a year, a month, and a day from the user. Include the print statements to output the following:or...
-
Consider school accountability reforms like the Common Core and No Child Left Behind in the context of the results found by Deming et al. (2016), discussed in the chapter. How might Demings results...
-
Contrast operating and financial leases.
-
Compare the assets of life insurance companies and commercial banks.
-
Abdulkadiroglu et al. (2011) studied the effectiveness of charter schools in the Boston area using a clever research strategy. They utilized the fact that many charter schools in the area are...
-
What goals have you developed for yourself in your career and/or in your workplace? What motivates you to reach these goals? In what ways does your motivation differ from that of other people you...
-
1) Describe the financial reporting environment in Australia. 2) Discuss what accounting is and the accounting process. 3) Discuss the Conceptual Framework and the objective of financial reporting....
-
What types of inventory issues Starbucks might reflect upon at the end of each year? The mission of Starbucks is to inspire and nurture the human spiritone person, one cup, and one neighborhood at a...
-
Rewrite Example C 8.80 using fgets, strtol, strtod, etc. (read the man pages), so that it is guaranteed not to result in buffer overflow.
-
In Fortran 77, local variables were typically allocated statically. In Algol and its descendants (e.g., Ada and C), they are typically allocated in the stack. In Lisp they are typically allocated at...
-
In several object-oriented languages, including C++ and Eiffel, a derived class can hide members of the base class. In C++, for example, we can declare a base class to be public, protected, or...
-
When nitrogen and fluorine combine to form a molecule, the most likely chemical formula is: (a) N 3 F. (b)N 2 F. (c) NF 4 . (d) NF. (e) NF 3 .
-
A substance consisting of which of the two molecules shown below should have a higher boiling point? Why? (a) the molecule on the left, SCO, because it comes later in the periodic table (b) the...
-
In terms of the periodic table, is there an abrupt or gradual change between ionic and covalent bonds? (a) An abrupt change occurs across the metalloids. (b) Actually, any element of the periodic...
Study smarter with the SolutionInn App