From 82ad71b3d406300b0868b5b99b2ae87f218a1a7e Mon Sep 17 00:00:00 2001 From: Oron Port Date: Wed, 10 Jan 2018 19:59:39 +0200 Subject: [PATCH 1/2] Clarify "the new" in dependent function types (also added missing `val`) I was skimming over at this documentation and it actually took me a while to notice what is new. So I added the comment to clarify. It is also possible to write `type EntryToKey = (e: Entry) => e.Key` and use it instead to clarify this is a dependent type --- docs/docs/reference/dependent-function-types.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/docs/reference/dependent-function-types.md b/docs/docs/reference/dependent-function-types.md index e32885773019..6a0e53da5a60 100644 --- a/docs/docs/reference/dependent-function-types.md +++ b/docs/docs/reference/dependent-function-types.md @@ -6,11 +6,14 @@ title: "Dependent Function Types" A dependent function type describes functions where the result type may depend on the function's parameter values. Example: - class Entry { type Key; key: Key } + class Entry { type Key; val key: Key } def extractKey(e: Entry): e.Key = e.key // a dependent method val extractor: (e: Entry) => e.Key = extractKey // a dependent function value - + // ║ ⇓ ⇓ ⇓ ⇓ ⇓ ⇓ ⇓ ║ + // ║ Dependent ║ + // ║ Function Type ║ + // ╚═══════════════════╝ Scala already has _dependent methods_, i.e. methods where the result type refers to some of the parameters of the method. Method `extractKey` is an example. Its result type, `e.key` refers its From 415525d11d30844217c510fb5d09df710a62ae5c Mon Sep 17 00:00:00 2001 From: Oron Port Date: Wed, 10 Jan 2018 20:51:42 +0200 Subject: [PATCH 2/2] changed `class` to trait since `key` is abstract --- docs/docs/reference/dependent-function-types.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/reference/dependent-function-types.md b/docs/docs/reference/dependent-function-types.md index 6a0e53da5a60..58c0d50d465a 100644 --- a/docs/docs/reference/dependent-function-types.md +++ b/docs/docs/reference/dependent-function-types.md @@ -6,7 +6,7 @@ title: "Dependent Function Types" A dependent function type describes functions where the result type may depend on the function's parameter values. Example: - class Entry { type Key; val key: Key } + trait Entry { type Key; val key: Key } def extractKey(e: Entry): e.Key = e.key // a dependent method val extractor: (e: Entry) => e.Key = extractKey // a dependent function value