Search for question
Question

4. Background: The num data type is composed of three variants: Inty of int: Represents an integer value. Floaty of float: Represents a floating-point value. Stringy of string: Represents a string which is guaranteed to be either a valid integer or a valid floating-point number. Objective: Define an infix operator +++ that sums 2 num values and returns a result of the num type, adhering to the following rules: Intv + Intv: Sum as integers, return as Intv. Floaty + Floaty: Sum as floats, return as (Floaty). Intv + Floaty Of Floaty + Inty: Convert the Intv to a float, sum as floats, and return as Floaty Stringy + any num type: Convert the stringy to its numeric representation (Intv) or Floaty ). Sum according to the rules above. Stringy + Stringy: Convert both stringy values to their numeric representations and sum the 2 values Return the result as stringy, converting the numeric result back to string format. Note: The conversion from stringy should account for the possibility that the string could represent either an integer or a float. The problem guarantees that the string will always be a valid representation of one of these two. 5. Write a function freq) that takes a list of strings and returns a hash table where the keys are the unique strings from the list and the values are their respective frequencies in the list. 6. Given a hash table that maps strings to integers (representing some kind of ID), write a function hashiny to create a new hash table where the integers map back to their original strings. Assume no two strings map to the same integer. 7. Write a program that computes the frequency of each string provided as command-line arguments. Your program should print the frequencies in the format "string count", where each string-count pair is on a separate line. The output should be ordered alphabetically based on the string. Hint: Consider using the Map module from the OCaml standard library to efficiently track the frequencies and obtain an ordered output. Input: Strings provided as command-line arguments, Example: ./prog apple banana apple cherry Output: Ordered string-count pairs printed line by line, e.g., apple 21 banana 1 cherry 1

Fig: 1