From 304adff4fa16ab9f2b2307ebc627b11e800dc741 Mon Sep 17 00:00:00 2001 From: YawarRaza7349 Date: Sat, 25 Nov 2023 18:00:19 -0800 Subject: [PATCH] Make open object type example more realistic Open object types exist to enable polymorphism, but the old example did not use open object types polymorphically. --- docs/object.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/object.md b/docs/object.md index a823ab3be..abeaca303 100644 --- a/docs/object.md +++ b/docs/object.md @@ -26,7 +26,7 @@ type car('a) = { } as 'a; ``` -Two dots, also called an elision, indicate that this is an "open" object type, and therefore can also contain other values and methods. An open object is also polymorphic and therefore requires a parameter. +Two dots, also called an elision, indicate that this is an "open" object type, and therefore can also contain other values and methods. An open object is also polymorphic and therefore requires a parameter. This parameter refers to the complete type of the object, including those other values and methods. ### Creation @@ -77,7 +77,9 @@ type tesla('a) = { drive: int => int } as 'a; -let obj: tesla({. drive: int => int, doYouWant: unit => bool}) = { +let driveInterstate = (t: tesla('a)) => t#drive(60); + +let obj: {. drive: int => int, doYouWant: unit => bool} = { val hasEnvy = ref(false); pub drive = (speed) => { this#enableEnvy(true); @@ -91,5 +93,6 @@ let obj: tesla({. drive: int => int, doYouWant: unit => bool}) = { You can use the above object like so: ```reason +driveInterstate(obj); obj#doYouWant(); ```