a splitting function, split_by Write a splitting function named split_by that takes three arguments an equality checking function...

70.2K

Verified Solution

Question

Programming

a splitting function, split_by

Write a splitting function named split_by that takes threearguments

  1. an equality checking function that takes two values and returnsa value of type bool,

  2. a list of values that are to be separated,

  3. and a list of separators values.

This function will split the second list into a list of lists.If the checking function indicates that an element of the firstlist (the second argument) is an element of the second list (thethird argument) then that element indicates that the list should besplit at that point. Note that this \"splitting element\" does notappear in any list in the output list of lists.

For example,

  • split_by (=) [1;2;3;4;5;6;7;8;9;10;11] [3;7] should evaluate to[ [1;2]; [4;5;6]; [8;9;10;11] ] and

  • split_by (=) [1;2;3;3;3;4;5;6;7;7;7;8;9;10;11] [3;7] shouldevaluate to [[1; 2]; []; []; [4; 5; 6]; []; []; [8; 9; 10;11]].

    Note the empty lists. These are the list that occur between the3's and 7's.

  • split_by (=) [\"A\"; \"B\"; \"C\"; \"D\"] [\"E\"] should evaluate to[[\"A\"; \"B\"; \"C\"; \"D\"]]

Annotate your function with types.

Also add a comment explaining the behavior of your function andits type. Try to write this function so that the type is as generalas possible.

OCaml code without using rec keyword in it.

Answer & Explanation Solved by verified expert
3.9 Ratings (458 Votes)
Given question we need to write splitbyfunction in ocaml taking three arguments below is snipet codewith detail implementation of accoriding to given points inquestion Three arguments include first equality operator secondlist and thirst    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students