Answered step by step
Verified Expert Solution
Question
1 Approved Answer
(* main variant type definition we will use throughout the assignment *) type json = | Num of float | String of string | False
(* main variant type definition we will use throughout the assignment *)
type json =
| Num of float
| String of string
| False
| True
| Null
| Array of json list
| Object of (string * json) list
This is the given ocaml json by using this and pattern matching please answer the following
Please use only pattern matching and not other built in ocaml methods as possible thank you so much!!!
In the next three problems, you will write two useful helper functions, then finally, write a function to convert from JSON to string, the key step in printing JSON values 2. Write a function concat_with that takes a separator string and a list of strings, and returns the string that consists of all the strings in the list concatenated together, separated by the separator. The separator should be only between elements, not at the beginning or end. Use OCaml's ^ operator for concatenation (e.g., "hello" " "world" evaluates to "helloworld"). Sample solution is 5 lines. 3. Write a function quote_string that takes a string and returns a string that is the same except there is an additional " character at the beginning and end. Sample solution is 1 line. 4. Write a function string_of_json that converts a json into the proper string encoding in terms of the syntax described on the first page of this assignment. The two previous problems are both helpful, but you will also want local helper functions for processing arrays and objects (hint: in both cases, create a string list that you then pass to concat_with). In the Num case, use the provided json_string_of_float function. Sample solution is 25 linesStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started