Suppose there are 2 2D shapes, Rect and Circle
# Rect.res
type t = {
width: float,
height: float,
x: float,
y: float,
}
let make = (width, height, ~x=0.0, ~y=0.0, ()) => {
{
width: width,
height: height,
x: x,
y: y,
}
}
# Cricle.res
type t = {
radius: float,
x: float,
y: float,
}
let make = (radius, ~x=0.0, ~y=0.0, ()) => {
{
radius: radius,
x: x,
y: y,
}
}
then, I want to define a common behavior that can move these two shapes
# Action.res
let move = (t, x, y) => {
{
...t,
x: x,
y: y,
}
}
but I got an error
The record field x can't be found.
If it's defined in another module or file, bring it into scope by:
- Prefixing it with said module name: TheModule.x
- Or specifying its type: let theValue: TheModule.theType = {x: VALUE}
I have experience in TypeScript development, but no ML related.
I hope I can learn some ways to get started from here, and it is better to have some small apps to provide learning.
thanks