如何解决如何使用变体选项在 rescript 中键入函数参数?
我想做以下事情。但似乎我无法使用变体选项之一键入函数参数。在 rescript 中实现这一目标的正确方法是什么?
chart
.render(document.getElementById('trust_chart'))
.catch(() => window.alert('Chart failed to initialise'));
}
解决方法
Teacher
和 Student
本身不是类型,而是构造 person
类型值的构造函数。如果您希望它们具有不同的类型,则必须使其明确:
module University = {
type subject = Math | History
type teacher = {firstName: string,subject: subject}
type student = {firstName: string}
type person =
| Teacher(teacher)
| Student(student)
let hasSameNameThanTeacher = (
~teacher: teacher,~student: student,) => {
teacher.firstName == student.firstName
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。