A temperature logger represents its readings using the following data definition:
Complete this plan for counting readings strictly above 25°C. For the operation blank, choose addition, multiplication, or maximum.
When the input is Empty, return . When the input is Link(value, next), apply the same counting function to . Use to combine that returned count with a contribution of 1 if value exceeds 25, or 0 otherwise.
Unlock full course notes by signing up
Decide which fields require a case check
A meal-order program uses dictionaries with a kind entry. Its data definition permits Counter(item_count) and Delivered(item_count, distance_km). Every valid value contains a positive integer item count; only Delivered values contain a nonnegative delivery distance. Assuming inputs satisfy this definition, which statements about function structure are true? Select all that apply.
Count the values a definition permits
An access-control program uses the following finite data definitions:
Grant has two fields: level, either viewer or editor; and expiry, either one day, one week, or one month.
Decision is either Deny, which has no fields, or Allow(grant), which contains one Grant.
Repair a nested-alternative calculation
A shipping program accepts valid parcel dictionaries. A Local parcel contains kind="local" and a positive weight_kg. An International parcel contains kind="international", a positive weight_kg, and a declaration dictionary. That declaration is either Documents, with only kind="documents", or Goods, with kind="goods" and a nonnegative value_dollars.
Local shipping costs 5.00 dollars per kilogram. International shipping costs 12.00 dollars plus 7.00 dollars per kilogram, with an additional 4% of declared value for Goods only. The following function fails for some valid inputs. Which correction makes it implement the stated charges for every permitted form?
Trace calls across nested data definitions
A file browser uses two data definitions:
Item is either File(size) or Folder(contents). File sizes are non-negative integers in bytes, and folder contents are an ItemList.
ItemList is either Empty() or Cons(first, rest), where first is an Item and rest is another ItemList.