Question: (* 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

(* main variant type definition we will use throughout the assignment *)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 lines

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!