diff --git a/pages/docs/manual/v11.0.0/generalized-algebraic-data-types.mdx b/pages/docs/manual/v11.0.0/generalized-algebraic-data-types.mdx index b60623817..8fa979892 100644 --- a/pages/docs/manual/v11.0.0/generalized-algebraic-data-types.mdx +++ b/pages/docs/manual/v11.0.0/generalized-algebraic-data-types.mdx @@ -118,13 +118,11 @@ Sometimes, a function should have a different return type based on what you give ```res example type rec number<_> = Int(int): number | Float(float): number -let add: - type a. (number, number) => a = - (a, b) => - switch (a, b) { - | (Int(a), Int(b)) => a + b - | (Float(a), Float(b)) => a +. b - } +let add = (type a, x: number, y: number): a => + switch (x, y) { + | (Int(x), Int(y)) => x + y + | (Float(x), Float(y)) => x +. y + } let foo = add(Int(1), Int(2)) @@ -145,26 +143,28 @@ module IfNotFound = { | DefaultTo('a): t<'a, 'a> } -let flexible_find: - type a b. (~f: a => bool, array, IfNotFound.t) => b = - (~f, arr, ifNotFound) => { - open IfNotFound - switch Array.find(arr, f) { - | None => - switch ifNotFound { - | Raise => failwith("No matching item found") - | ReturnNone => None - | DefaultTo(x) => x - } - | Some(x) => - switch ifNotFound { - | ReturnNone => Some(x) - | Raise => x - | DefaultTo(_) => x - } +let flexible_find = ( + type a b, + ~f: a => bool, + arr: array, + ifNotFound: IfNotFound.t, +): b => { + open IfNotFound + switch Array.find(arr, f) { + | None => + switch ifNotFound { + | Raise => failwith("No matching item found") + | ReturnNone => None + | DefaultTo(x) => x + } + | Some(x) => + switch ifNotFound { + | ReturnNone => Some(x) + | Raise => x + | DefaultTo(_) => x } } - +} ``` ## Hide and recover Type information Dynamically diff --git a/pages/docs/manual/v12.0.0/generalized-algebraic-data-types.mdx b/pages/docs/manual/v12.0.0/generalized-algebraic-data-types.mdx index 42a9df049..efa58a3d1 100644 --- a/pages/docs/manual/v12.0.0/generalized-algebraic-data-types.mdx +++ b/pages/docs/manual/v12.0.0/generalized-algebraic-data-types.mdx @@ -118,13 +118,11 @@ Sometimes, a function should have a different return type based on what you give ```res example type rec number<_> = Int(int): number | Float(float): number -let add: - type a. (number, number) => a = - (a, b) => - switch (a, b) { - | (Int(a), Int(b)) => a + b - | (Float(a), Float(b)) => a +. b - } +let add = (type a, x: number, y: number): a => + switch (x, y) { + | (Int(x), Int(y)) => x + y + | (Float(x), Float(y)) => x +. y + } let foo = add(Int(1), Int(2)) @@ -145,26 +143,28 @@ module IfNotFound = { | DefaultTo('a): t<'a, 'a> } -let flexible_find: - type a b. (~f: a => bool, array, IfNotFound.t) => b = - (~f, arr, ifNotFound) => { - open IfNotFound - switch Array.find(arr, f) { - | None => - switch ifNotFound { - | Raise => failwith("No matching item found") - | ReturnNone => None - | DefaultTo(x) => x - } - | Some(x) => - switch ifNotFound { - | ReturnNone => Some(x) - | Raise => x - | DefaultTo(_) => x - } +let flexible_find = ( + type a b, + ~f: a => bool, + arr: array, + ifNotFound: IfNotFound.t, +): b => { + open IfNotFound + switch Array.find(arr, f) { + | None => + switch ifNotFound { + | Raise => failwith("No matching item found") + | ReturnNone => None + | DefaultTo(x) => x + } + | Some(x) => + switch ifNotFound { + | ReturnNone => Some(x) + | Raise => x + | DefaultTo(_) => x } } - +} ``` ## Hide and recover Type information Dynamically