Why is inserting this string into a record throwing an error?

54 Views Asked by At

I am trying to insert a string into a record type, which is a list of strings. However, the semicolon after the record keeps throwing an error. Also a couple of lines down there's a type error that I think is related because as I've been playing around with debugging the first error sometimes it goes away. Deleting the semicolon, adding or deleting "...", "_", or the entire record hasn't worked and often only causes more errors.

if (lecture.time == workweek.time) {
  switch (lecture.priority, workweek.priority) {
  | (3, 1) => failwith("No time available for class")
  | (3, 2) => 
    switch (lecture.day) {
    | "monday" => {monday: [lecture.lecture], ...};
    | "tuesday" => {..., tuesday: [lecture.lecture], ...};
    | "wednesday" => {..., wednesday: [lecture.lecture], ...};
    | "thursday" => {..., thursday: [lecture.lecture], ...};
    | "friday" => {..., friday: [lecture.lecture]};
    | _ => failwith ("not a valid day")

The errors:

Error: Syntax error
Error: This pattern matches values of type string
       but a pattern was expected which matches values of type (int, int)
1

There are 1 best solutions below

0
Yawar On

Record update syntax is {...rec, field: value}: https://reasonml.github.io/docs/en/record#updating-records-amp-spreading

In your case it should probably be:

{...lecture, monday: [lecture.lecture]}

But it's difficult to be sure without knowing the definition of the record type. You should also list the errors next to the specific code that throws each error, not lump them together. It's difficult to tell which code is causing which error.