Skip to content

Add Enum Eq #2552

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
May 29, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions docs/docs/reference/named-typeargs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
layout: doc-page
title: "Named Type Arguments"
---
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would also be great to have a page about implicit function types.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coming up...


Type arguments of methods can now be named as well as by position. Example:


def construct[Elem, Coll[_]](xs: Elem*): Coll[Elem] = ???

val xs2 = construct[Coll = List, Elem = Int](1, 2, 3)
val xs3 = construct[Coll = List](1, 2, 3)

Similar to a named value argument `(x = e)`, a named type argument
`[X = T]` instantiates the type parameter `X` to the type `T`. Type
arguments must be all named or un-named, mixtures of named and
positional type arguments are not supported.

The main benefit of named type arguments is that they allow some
arguments to be omitted. Indeed, if type arguments are named, some
arguments may be left out. An example is the definition of `xs3`
above. A missing type argument is inferred as usual by local type
inference. The same is not true for positional arguments, which have
to be given always for all type parameters.

2 changes: 2 additions & 0 deletions docs/sidebar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ sidebar:
url: docs/reference/implicit-by-name-parameters.htmldocs/reference/implicit-by-name-parameters.html
- title: Auto Parameter Tupling
url: docs/reference/auto-parameter-tupling.html
- title: Named Type Arguments
url: docs/reference/named-typeargs.html
- title: Usage
subsection:
- title: sbt-projects
Expand Down
13 changes: 13 additions & 0 deletions tests/pos/reference/named-typeargs.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package namedTypeArgsR {

object t1 {

def construct[Elem, Coll[_]](xs: Elem*): Coll[Elem] = ???

val xs3 = construct[Coll = List](1, 2, 3)

val xs2 = construct[Coll = List, Elem = Int](1, 2, 3)

}

}