Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribedPlease 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Visual Basic 6 Databases

Authors: Charles Williams

1st Edition

1861002025, 978-1861002020

More Books

Students also viewed these Databases questions

Question

2. How do these vengeful heroes exorcise their daemons?

Answered: 1 week ago

Question

What is a verb?

Answered: 1 week ago