From e03612ea9e7d1bcb253cf206ae18c4842992bf97 Mon Sep 17 00:00:00 2001 From: Rea Sand Date: Thu, 18 Oct 2018 11:57:50 +0200 Subject: [PATCH 01/11] docs: consistently use Option instead of Optional --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 1a1e23b..943a8d5 100644 --- a/readme.md +++ b/readme.md @@ -950,7 +950,7 @@ times(-1)(console.log) // RangeError: Maximum call stack size exceeded ``` ### Avoiding partial functions -Partial functions are dangerous, you can sometimes get the expected result, sometimes the wrong result, and sometimes your function can't stop the calculations at all. The input of partial functions should be always checked, and it can be hard to track all edge cases through entire applications, the easiest way to deal with it it's just to convert all partial functions to the total. General advice can be the usage of `Optional` type, providing default values for edge cases and checking function conditions to make them always terminate: +Partial functions are dangerous, you can sometimes get the expected result, sometimes the wrong result, and sometimes your function can't stop the calculations at all. The input of partial functions should be always checked, and it can be hard to track all edge cases through entire applications, the easiest way to deal with it it's just to convert all partial functions to the total. General advice can be the usage of `Option` type, providing default values for edge cases and checking function conditions to make them always terminate: ```js // example 1: sum of the list // we can provide default value so it will always return result From a7e26ce75613a24e6278e66f9369ce5a42030ed4 Mon Sep 17 00:00:00 2001 From: Rea Sand Date: Thu, 18 Oct 2018 11:59:54 +0200 Subject: [PATCH 02/11] fix: drop trailing whitespace --- readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 943a8d5..6531c19 100644 --- a/readme.md +++ b/readme.md @@ -946,7 +946,7 @@ times(3)(console.log) // 3 // 2 // 1 -times(-1)(console.log) +times(-1)(console.log) // RangeError: Maximum call stack size exceeded ``` ### Avoiding partial functions @@ -980,7 +980,7 @@ times(3)(console.log) // 3 // 2 // 1 -times(-1)(console.log) +times(-1)(console.log) // won't execute anything ``` If you will change all your functions from partial to total, it can prevent you from having runtime exceptions, will make code easier to reason about and easier to maintain. From 321806908c875ee40e63dbe77a1d95870195cbc1 Mon Sep 17 00:00:00 2001 From: Rea Sand Date: Fri, 19 Oct 2018 15:21:43 +0200 Subject: [PATCH 03/11] refactor: Introduce function section - dissolve totality section - make partial function a top-level section - reformulate content of partial function section --- readme.md | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/readme.md b/readme.md index 6531c19..7f8a2ed 100644 --- a/readme.md +++ b/readme.md @@ -60,7 +60,8 @@ __Table of Contents__ * [Sum type](#sum-type) * [Product type](#product-type) * [Option](#option) -* [Totality](#totality) +* [Function](#function) +* [Partial function](#partial-function) * [Functional Programming Libraries in JavaScript](#functional-programming-libraries-in-javascript) @@ -908,9 +909,12 @@ getNestedPrice({item: {price: 9.99}}) // Some(9.99) `Option` is also known as `Maybe`. `Some` is sometimes called `Just`. `None` is sometimes called `Nothing`. -## Totality -### Total functions -The total function is just like a function in math - it will always return a result of the expected type for expected inputs and will always terminate. The easiest example is `identity` function: +## Function +Category Threory: A function is just an arrow between types. It has a direction. Replace arrow with mapping maybe? + +A **function** `f: A -> B` maps every element from its domain (A) to an element in its co-domain (B); or in other words: takes exactly one argument and maps it to exactly one (and always the same) value. That value depends entirely on the argument. This is what makes functions so pleasant to work with: there is no room for side-effects; a function is always pure – by definition. Functions exhibit [referential transparency](#referential-transparency). + +A very simple example is the `identity` function: ```js // identity :: a -> a const identity = a => a @@ -920,9 +924,24 @@ or `negate`: // negate :: Boolean -> Boolean const negate = value => !value ``` -Such functions always meet the requirements, you just can't provide such arguments, which satisfy inputs but break outputs. -### Partial functions -It's a function which violates the requirements to be total - it may return an unexpected result with some inputs or it may never terminate. Partial functions add cognitive overhead, they are harder to reason about and they can lead to runtime errors. Some examples: + +When programmers talk about functions though they often mean **expressions**: methods, procedures, and the likes. This is where some of the misconceptions regarding e.g. [Purity](#purity) and [Side effects](#side-effects) as special to some subset of functions come from, so that they need to be adressed here. What we really mean to say is: An expression which does not produce any side-effects (or: is pure) is a function. Programmers also have a concept of *functions expecting more than one parameter*, although those are *convenience methods* for their [curried forms](#currying). And rightfully so! Convenience is an important aspect of programming. + +```js +// not a function, but an expression or more specifically a method +// add :: (number, number) -> number +const add = (a, b) => a + b + +// add :: number => number => number +// curried form: a function - taking one argument and returning a value, in this case another function +const addCurried = a => b => a + b +add(1, 2) // might be considered more convenient than addCurried(1)(2) +``` + +It's totally fine to use the term "function" in a more loose way – depending on context –, but keep in mind its original meaning as *side-effect-free* or *pure* is often implicit with resources like the documentation of your favourite [fp libraries](#functional-programming-libraries-in-javascript). + +## Partial function +A partial function is a function which may not be defined for all inputs - it might return an unexpected result with some inputs or it may never terminate. Partial functions add cognitive overhead, they are harder to reason about and they can lead to runtime errors. Some examples: ```js // example 1: sum of the list // sum :: [Number] -> Number @@ -949,8 +968,10 @@ times(3)(console.log) times(-1)(console.log) // RangeError: Maximum call stack size exceeded ``` -### Avoiding partial functions -Partial functions are dangerous, you can sometimes get the expected result, sometimes the wrong result, and sometimes your function can't stop the calculations at all. The input of partial functions should be always checked, and it can be hard to track all edge cases through entire applications, the easiest way to deal with it it's just to convert all partial functions to the total. General advice can be the usage of `Option` type, providing default values for edge cases and checking function conditions to make them always terminate: + +### Dealing with partial functions +Partial functions are dangerous as they need to be treated with great caution. You might get an unexpected (wrong) result or run into runtime errors. Sometimes a partial function might not return at all. Being aware of and treating all these edge cases accordingly can become very tedious. +Fortunately a partial function can be converted to a regular (or total) one. We can provide default values or use guards to deal with inputs for which the (previously) partial function is undefined. Utilizing the [`Option`](#Option) type, we can yield either `Some(value)` or `None` where we would otherwise have behaved unexpectedly: ```js // example 1: sum of the list // we can provide default value so it will always return result @@ -963,7 +984,7 @@ sqrt([]) // 0 // change result to Option // first :: [A] -> Option A const first = a => a.length ? Some(a[0]) : None() -first([[42]]).map(a => console.log(a)) // 42 +first([42]).map(a => console.log(a)) // 42 first([]).map(a => console.log(a)) // console.log won't execute at all //our previous worst case first([[42]]).map(a => console.log(a[0])) // 42 @@ -983,7 +1004,7 @@ times(3)(console.log) times(-1)(console.log) // won't execute anything ``` -If you will change all your functions from partial to total, it can prevent you from having runtime exceptions, will make code easier to reason about and easier to maintain. +Making your partial functions total ones, these kinds of runtime errors can be prevented. Always returning a value will also make for code that is both easier to maintain as well as to reason about. ## Functional Programming Libraries in JavaScript From c77168a62c923aae444de0c4c622edd50566c2d4 Mon Sep 17 00:00:00 2001 From: Rea Sand Date: Mon, 29 Oct 2018 09:51:19 +0100 Subject: [PATCH 04/11] chore: Minor adjustments to function section --- readme.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/readme.md b/readme.md index 7f8a2ed..0a4c2ac 100644 --- a/readme.md +++ b/readme.md @@ -910,9 +910,7 @@ getNestedPrice({item: {price: 9.99}}) // Some(9.99) `Option` is also known as `Maybe`. `Some` is sometimes called `Just`. `None` is sometimes called `Nothing`. ## Function -Category Threory: A function is just an arrow between types. It has a direction. Replace arrow with mapping maybe? - -A **function** `f: A -> B` maps every element from its domain (A) to an element in its co-domain (B); or in other words: takes exactly one argument and maps it to exactly one (and always the same) value. That value depends entirely on the argument. This is what makes functions so pleasant to work with: there is no room for side-effects; a function is always pure – by definition. Functions exhibit [referential transparency](#referential-transparency). +A **function** `f: A -> B` maps every element of type A to an element of type B. It takes *exactly one* argument and maps it to exactly one (and always the same) value. That value depends entirely on the argument. This is what makes functions so pleasant to work with: there is no room for side-effects; a function is always pure – by definition. Functions exhibit [referential transparency](#referential-transparency) which allow for [equational reasoning](#equational-reasoning). A very simple example is the `identity` function: ```js @@ -925,7 +923,7 @@ or `negate`: const negate = value => !value ``` -When programmers talk about functions though they often mean **expressions**: methods, procedures, and the likes. This is where some of the misconceptions regarding e.g. [Purity](#purity) and [Side effects](#side-effects) as special to some subset of functions come from, so that they need to be adressed here. What we really mean to say is: An expression which does not produce any side-effects (or: is pure) is a function. Programmers also have a concept of *functions expecting more than one parameter*, although those are *convenience methods* for their [curried forms](#currying). And rightfully so! Convenience is an important aspect of programming. +When programmers talk about functions though they often mean **expressions**: methods, procedures, and the likes. This is where some of the misconceptions regarding e.g. [purity](#purity) and [side effects](#side-effects) as special to some subset of function come from. What we really mean to say is: An expression which does not produce any side-effects (or: is pure) is a function. Programmers also have a concept of *functions expecting more than one parameter*, although those are *convenience methods* for their [curried forms](#currying). And rightfully so! Convenience is an important aspect of programming. ```js // not a function, but an expression or more specifically a method From 1e8238608b368d608f38f5ad2d82d47533ace729 Mon Sep 17 00:00:00 2001 From: Rea Sand Date: Sat, 3 Nov 2018 18:37:23 +0100 Subject: [PATCH 05/11] refactor: function - more concise wording --- readme.md | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/readme.md b/readme.md index 0a4c2ac..95873f7 100644 --- a/readme.md +++ b/readme.md @@ -910,33 +910,28 @@ getNestedPrice({item: {price: 9.99}}) // Some(9.99) `Option` is also known as `Maybe`. `Some` is sometimes called `Just`. `None` is sometimes called `Nothing`. ## Function -A **function** `f: A -> B` maps every element of type A to an element of type B. It takes *exactly one* argument and maps it to exactly one (and always the same) value. That value depends entirely on the argument. This is what makes functions so pleasant to work with: there is no room for side-effects; a function is always pure – by definition. Functions exhibit [referential transparency](#referential-transparency) which allow for [equational reasoning](#equational-reasoning). - -A very simple example is the `identity` function: -```js -// identity :: a -> a -const identity = a => a -``` -or `negate`: -```js -// negate :: Boolean -> Boolean -const negate = value => !value -``` - -When programmers talk about functions though they often mean **expressions**: methods, procedures, and the likes. This is where some of the misconceptions regarding e.g. [purity](#purity) and [side effects](#side-effects) as special to some subset of function come from. What we really mean to say is: An expression which does not produce any side-effects (or: is pure) is a function. Programmers also have a concept of *functions expecting more than one parameter*, although those are *convenience methods* for their [curried forms](#currying). And rightfully so! Convenience is an important aspect of programming. +#### Definition +A **function** is a special kind of language construct: often specified as an arrow or lambda expression - an anonymous or named block of code (the body) with optional parameters. It allows us to treat a piece of code as data and e.g. pass it to methods: ```js -// not a function, but an expression or more specifically a method -// add :: (number, number) -> number -const add = (a, b) => a + b - -// add :: number => number => number -// curried form: a function - taking one argument and returning a value, in this case another function -const addCurried = a => b => a + b -add(1, 2) // might be considered more convenient than addCurried(1)(2) +button.onClick(e => console.log("the button has been clicked")) // valid function, but with a side effect (see below) ``` -It's totally fine to use the term "function" in a more loose way – depending on context –, but keep in mind its original meaning as *side-effect-free* or *pure* is often implicit with resources like the documentation of your favourite [fp libraries](#functional-programming-libraries-in-javascript). +```js +// times2 :: Number -> Number +const times2 = n => n * 2 + +[1, 2, 3].map(times2) // [2, 4, 6] +``` + +#### Differentiation +Functional programming has its origins in mathematics and so do a lot of its terms. We hence need to differentiate between the concept of a function and its implementation as a language construct (as outlined above): In terms of set theory, a function `f: X -> Y` is an arrow between two sets `X` and `Y`. It maps *every* element in its *domain* `X` to an element in its *codomain* `Y` (note the use of singular here). + + +Translating this into the language of computer science, a function is an expression with **exactly one (immutable)** parameter and **exactly one** return value. That value depends entirely on the argument which makes functions context-independant. This property is called [referential transparency](#referential-transparency) which allows for [equational reasoning](#equational-reasoning). Its mathematical origin also necessitates the absence of hidden [side effects](#side-effects) - a function is always [pure](#purity), by definition. These features make functions (as defined by mathematics) so pleasant to work with: they are entirely deterministic and therefore predictable. + + +Contrast this with the definition above: none of the aforementioned constrains are baked into the language constructs we need to deal with. They have been sacrificed in part for pragmatism, convenience, and expressiveness - useful features of programming languages. This mismatch the concept of a function and its concrete implementation must be accounted for by the programmer; she must appreciate the principles functional programming is grounded on in order to benefit from its promises. ## Partial function A partial function is a function which may not be defined for all inputs - it might return an unexpected result with some inputs or it may never terminate. Partial functions add cognitive overhead, they are harder to reason about and they can lead to runtime errors. Some examples: From 0ce557945eb72042c3cb3da1a1784a69d6d062d0 Mon Sep 17 00:00:00 2001 From: Rea Sand Date: Sat, 3 Nov 2018 18:39:52 +0100 Subject: [PATCH 06/11] chore: Remove inline comment --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 95873f7..1cb2850 100644 --- a/readme.md +++ b/readme.md @@ -914,7 +914,7 @@ getNestedPrice({item: {price: 9.99}}) // Some(9.99) A **function** is a special kind of language construct: often specified as an arrow or lambda expression - an anonymous or named block of code (the body) with optional parameters. It allows us to treat a piece of code as data and e.g. pass it to methods: ```js -button.onClick(e => console.log("the button has been clicked")) // valid function, but with a side effect (see below) +button.onClick(e => console.log("the button has been clicked")) ``` ```js From 5ee03c4877362edc763198d5fcb3ee568035e517 Mon Sep 17 00:00:00 2001 From: Rea Sand Date: Sat, 3 Nov 2018 18:42:54 +0100 Subject: [PATCH 07/11] chore: function - Add forgotten word --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 1cb2850..a8ef6d6 100644 --- a/readme.md +++ b/readme.md @@ -931,7 +931,7 @@ Functional programming has its origins in mathematics and so do a lot of its ter Translating this into the language of computer science, a function is an expression with **exactly one (immutable)** parameter and **exactly one** return value. That value depends entirely on the argument which makes functions context-independant. This property is called [referential transparency](#referential-transparency) which allows for [equational reasoning](#equational-reasoning). Its mathematical origin also necessitates the absence of hidden [side effects](#side-effects) - a function is always [pure](#purity), by definition. These features make functions (as defined by mathematics) so pleasant to work with: they are entirely deterministic and therefore predictable. -Contrast this with the definition above: none of the aforementioned constrains are baked into the language constructs we need to deal with. They have been sacrificed in part for pragmatism, convenience, and expressiveness - useful features of programming languages. This mismatch the concept of a function and its concrete implementation must be accounted for by the programmer; she must appreciate the principles functional programming is grounded on in order to benefit from its promises. +Contrast this with the definition above: none of the aforementioned constrains are baked into the language constructs we need to deal with. They have been sacrificed in part for pragmatism, convenience, and expressiveness - useful features of programming languages. This mismatch between the concept of a function and its concrete implementation must be accounted for by the programmer; she must appreciate the principles functional programming is grounded on in order to benefit from its promises. ## Partial function A partial function is a function which may not be defined for all inputs - it might return an unexpected result with some inputs or it may never terminate. Partial functions add cognitive overhead, they are harder to reason about and they can lead to runtime errors. Some examples: From c878e19ca7604d4037f189fff3c85996ef2114be Mon Sep 17 00:00:00 2001 From: Rea Sand Date: Sat, 3 Nov 2018 18:48:52 +0100 Subject: [PATCH 08/11] refactor: function - drop superfluous sentence --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index a8ef6d6..209ef49 100644 --- a/readme.md +++ b/readme.md @@ -931,7 +931,7 @@ Functional programming has its origins in mathematics and so do a lot of its ter Translating this into the language of computer science, a function is an expression with **exactly one (immutable)** parameter and **exactly one** return value. That value depends entirely on the argument which makes functions context-independant. This property is called [referential transparency](#referential-transparency) which allows for [equational reasoning](#equational-reasoning). Its mathematical origin also necessitates the absence of hidden [side effects](#side-effects) - a function is always [pure](#purity), by definition. These features make functions (as defined by mathematics) so pleasant to work with: they are entirely deterministic and therefore predictable. -Contrast this with the definition above: none of the aforementioned constrains are baked into the language constructs we need to deal with. They have been sacrificed in part for pragmatism, convenience, and expressiveness - useful features of programming languages. This mismatch between the concept of a function and its concrete implementation must be accounted for by the programmer; she must appreciate the principles functional programming is grounded on in order to benefit from its promises. +Contrast this with the definition above: none of the aforementioned constrains are baked into the language constructs we need to deal with. They have been sacrificed in part for pragmatism, convenience, and expressiveness - useful features of programming languages. This mismatch between the concept of a function and its concrete implementation must be accounted for by the programmer. ## Partial function A partial function is a function which may not be defined for all inputs - it might return an unexpected result with some inputs or it may never terminate. Partial functions add cognitive overhead, they are harder to reason about and they can lead to runtime errors. Some examples: From ccd128abb552b27f0894d831927ba5ca946bf5bf Mon Sep 17 00:00:00 2001 From: Rea Sand Date: Sat, 3 Nov 2018 19:28:43 +0100 Subject: [PATCH 09/11] refactor: function - rephrasing the last paragraph --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 209ef49..8f516a2 100644 --- a/readme.md +++ b/readme.md @@ -931,7 +931,7 @@ Functional programming has its origins in mathematics and so do a lot of its ter Translating this into the language of computer science, a function is an expression with **exactly one (immutable)** parameter and **exactly one** return value. That value depends entirely on the argument which makes functions context-independant. This property is called [referential transparency](#referential-transparency) which allows for [equational reasoning](#equational-reasoning). Its mathematical origin also necessitates the absence of hidden [side effects](#side-effects) - a function is always [pure](#purity), by definition. These features make functions (as defined by mathematics) so pleasant to work with: they are entirely deterministic and therefore predictable. -Contrast this with the definition above: none of the aforementioned constrains are baked into the language constructs we need to deal with. They have been sacrificed in part for pragmatism, convenience, and expressiveness - useful features of programming languages. This mismatch between the concept of a function and its concrete implementation must be accounted for by the programmer. +Contrast this with the definition above: none of the aforementioned constrains are baked into the language constructs we need to deal with. They have been sacrificed in part for pragmatism, convenience, and expressiveness - useful, powerful, and at times dangerous features of programming languages. This mismatch between the concept of a function and its concrete implementation must be accounted for by the programmer if she wants to benefit from the promises of functional programming. ## Partial function A partial function is a function which may not be defined for all inputs - it might return an unexpected result with some inputs or it may never terminate. Partial functions add cognitive overhead, they are harder to reason about and they can lead to runtime errors. Some examples: From c23510813e87284ff4f0d6239fc7b9c3bb925120 Mon Sep 17 00:00:00 2001 From: Rea Sand Date: Sun, 11 Nov 2018 13:47:22 +0100 Subject: [PATCH 10/11] refactor: function - drastically shorten content --- readme.md | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/readme.md b/readme.md index 8f516a2..144bb83 100644 --- a/readme.md +++ b/readme.md @@ -910,12 +910,7 @@ getNestedPrice({item: {price: 9.99}}) // Some(9.99) `Option` is also known as `Maybe`. `Some` is sometimes called `Just`. `None` is sometimes called `Nothing`. ## Function -#### Definition -A **function** is a special kind of language construct: often specified as an arrow or lambda expression - an anonymous or named block of code (the body) with optional parameters. It allows us to treat a piece of code as data and e.g. pass it to methods: - -```js -button.onClick(e => console.log("the button has been clicked")) -``` +A **function** `f :: A => B` is an expression - often called arrow or lambda expression - with **exactly one (immutable)** parameter of type `A` and **exactly one** return value of type `B`. That value depends entirely on the argument, making functions context-independant, or [referentially transparent](#referential-transparency). What is implied here is that a function must not produce any hidden [side effects](#side-effects) - a function is always [pure](#purity), by definition. These properties make functions pleasant to work with: they are entirely deterministic and therefore predictable. Functions enable working with code as data, abstracting over behaviour: ```js // times2 :: Number -> Number @@ -924,15 +919,6 @@ const times2 = n => n * 2 [1, 2, 3].map(times2) // [2, 4, 6] ``` -#### Differentiation -Functional programming has its origins in mathematics and so do a lot of its terms. We hence need to differentiate between the concept of a function and its implementation as a language construct (as outlined above): In terms of set theory, a function `f: X -> Y` is an arrow between two sets `X` and `Y`. It maps *every* element in its *domain* `X` to an element in its *codomain* `Y` (note the use of singular here). - - -Translating this into the language of computer science, a function is an expression with **exactly one (immutable)** parameter and **exactly one** return value. That value depends entirely on the argument which makes functions context-independant. This property is called [referential transparency](#referential-transparency) which allows for [equational reasoning](#equational-reasoning). Its mathematical origin also necessitates the absence of hidden [side effects](#side-effects) - a function is always [pure](#purity), by definition. These features make functions (as defined by mathematics) so pleasant to work with: they are entirely deterministic and therefore predictable. - - -Contrast this with the definition above: none of the aforementioned constrains are baked into the language constructs we need to deal with. They have been sacrificed in part for pragmatism, convenience, and expressiveness - useful, powerful, and at times dangerous features of programming languages. This mismatch between the concept of a function and its concrete implementation must be accounted for by the programmer if she wants to benefit from the promises of functional programming. - ## Partial function A partial function is a function which may not be defined for all inputs - it might return an unexpected result with some inputs or it may never terminate. Partial functions add cognitive overhead, they are harder to reason about and they can lead to runtime errors. Some examples: ```js From ead281f50ea0051219ca2fd6ee568799b1966224 Mon Sep 17 00:00:00 2001 From: Rea Sand Date: Sun, 11 Nov 2018 13:58:43 +0100 Subject: [PATCH 11/11] refactor: partial function - Minor adjustments --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 144bb83..94a50c6 100644 --- a/readme.md +++ b/readme.md @@ -920,7 +920,7 @@ const times2 = n => n * 2 ``` ## Partial function -A partial function is a function which may not be defined for all inputs - it might return an unexpected result with some inputs or it may never terminate. Partial functions add cognitive overhead, they are harder to reason about and they can lead to runtime errors. Some examples: +A partial function is a [function](#function) which is not defined for all arguments - it might return an unexpected result or may never terminate. Partial functions add cognitive overhead, they are harder to reason about and can lead to runtime errors. Some examples: ```js // example 1: sum of the list // sum :: [Number] -> Number