I'm sorry if my vernacular is wrong here. I'm very new to coding.
I have created two records. I want my program to take in these two records. However, in the type signature both of the items are classified as the second record. I'm not sure how heavily this is impacting the program, but it's beginning to throw more errors due to this problem.
I've tried changing the orders around but I've never encountered a problem like this so I'm kind of at a loss. Is there a way to manually put in what I want the types of the type signature to be?
type lecture = {
lecture: string,
day: string,
time: list(int),
priority: int,
};
type workweek = {
day: string,
time: list(int),
priority: int,
};
let schedSorter = (lecture, workweek) =>
if (lecture.time == workweek.time) {
switch (lecture.priority, workweek.priority)
When using two record types with common field names, one may need to help the typechecker to disambiguate between the two types.
For instance, consider this line:
It is impossible to look at this line and deduce that
lectureought to have typelecturewhileworkweekhas typeworkweekwithout some more information. And type inference is always local. In such ambiguous situation, the typechecker always pick the last defned types as the default option.It is possible to avoid this ambiguous choice in a few ways.
With this definition, we are now able to distinguish the field
Lecture.priorityfrom the fieldWorkweek.priority. Thus, the ambiguous linecan be clarified as
lecturetype contains aworkweek, thus it might work to rewrite thelecturetype aswhich completely avoids the ambiguity of duplicated field names.