You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pages/docs/manual/latest/module.mdx
+14-14Lines changed: 14 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -413,22 +413,22 @@ type state = int
413
413
let render: string => string
414
414
```
415
415
416
-
## Module Functions (functors)
416
+
## Module Functions
417
417
418
418
Modules can be passed to functions! It would be the equivalent of passing a file
419
419
as a first-class item. However, modules are at a different "layer" of the
420
420
language than other common concepts, so we can't pass them to *regular*
421
-
functions. Instead, we pass them to special functions called "functors".
421
+
functions. Instead, we pass them to special functions called module functions.
422
422
423
-
The syntax for defining and using functors is very much like the syntax
423
+
The syntax for defining and using module functions is very much like the syntax
424
424
for defining and using regular functions. The primary differences are:
425
425
426
-
-Functors use the `module` keyword instead of `let`.
427
-
-Functors take modules as arguments and return a module.
428
-
-Functors*require* annotating arguments.
429
-
-Functors must start with a capital letter (just like modules/signatures).
426
+
-Module functions use the `module` keyword instead of `let`.
427
+
-Module functions take modules as arguments and return a module.
428
+
-Module functions*require* annotating arguments.
429
+
-Module functions must start with a capital letter (just like modules/signatures).
430
430
431
-
Here's an example `MakeSet`functor, that takes in a module of the type
431
+
Here's an example `MakeSet`module function, that takes in a module of the type
432
432
`Comparable` and returns a new set that can contain such comparable items.
433
433
434
434
<CodeTablabels={["ReScript", "JS Output"]}>
@@ -482,7 +482,7 @@ function MakeSet(Item) {
482
482
483
483
</CodeTab>
484
484
485
-
Functors can be applied using function application syntax. In this case, we're
485
+
Module functions can be applied using function application syntax. In this case, we're
486
486
creating a set, whose items are pairs of integers.
487
487
488
488
<CodeTablabels={["ReScript", "JS Output"]}>
@@ -525,12 +525,12 @@ var SetOfIntPairs = {
525
525
526
526
### Module functions types
527
527
528
-
Like with module types, functor types also act to constrain and hide what we may
529
-
assume about functors. The syntax for functor types are consistent with those
528
+
Like with module types, module function types also act to constrain and hide what we may
529
+
assume about module functions. The syntax for module function types are consistent with those
530
530
for function types, but with types capitalized to represent the signatures of
531
-
modules the functor accepts as arguments and return values. In the
531
+
modules the module functions accepts as arguments and return values. In the
532
532
previous example, we're exposing the backing type of a set; by giving `MakeSet`
533
-
a functor signature, we can hide the underlying data structure!
533
+
a module function signature, we can hide the underlying data structure!
534
534
535
535
<CodeTablabels={["ReScript", "JS Output"]}>
536
536
@@ -566,4 +566,4 @@ Please note that modules with an exotic filename will not be accessible from oth
566
566
567
567
## Tips & Tricks
568
568
569
-
Modules and functors are at a different "layer" of language than the rest (functions, let bindings, data structures, etc.). For example, you can't easily pass them into a tuple or record. Use them judiciously, if ever! Lots of times, just a record or a function is enough.
569
+
Modules and module functions are at a different "layer" of language than the rest (functions, let bindings, data structures, etc.). For example, you can't easily pass them into a tuple or record. Use them judiciously, if ever! Lots of times, just a record or a function is enough.
0 commit comments