Skip to content

Commit

Permalink
Adjustments to layout, + syncing with Josh.
Browse files Browse the repository at this point in the history
  • Loading branch information
heathermiller committed Oct 14, 2011
1 parent d60e3c4 commit 9a844a6
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 189 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_site
6 changes: 3 additions & 3 deletions _layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@
<div class="row">
<h1>{{ site.title }}</h1>
{% if page.title %}<h1>{{ page.title }}</h1>{% endif %}
<div class="span12">
<div class="span10">
{{ content }}
{% if page.disqus == true %}#DISQUS!!#{% include disqus.txt %}{% endif %}
{% if page.disqus == true %}{% include disqus.txt %}{% endif %}
</div>
{% if page.type == 'sip' %}
<div class="span4">
<div class="span6">
{% include allsids.txt %}
</div>
{% endif %}
Expand Down
12 changes: 0 additions & 12 deletions sips/draft/_posts/2011-10-12-implicit-classes.md

This file was deleted.

162 changes: 0 additions & 162 deletions sips/draft/_posts/2011-10-12-inline-classes.md

This file was deleted.

83 changes: 83 additions & 0 deletions sips/pending/_posts/2011-10-12-implicit-classes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
layout: default
type: sip
title: SIP-13 - Implicit classes
---

This SIP is based on [this pre-draft](https://docs.google.com/document/d/1k-aGAGmbrDB-2pJ3uDPpHVKno6p-XbnkVHDc07zPrzQ/edit?hl=en_US).

Material adapted from [http://jorgeortiz85.github.com/ImplicitClassSIP.xhtml](http://jorgeortiz85.github.com/ImplicitClassSIP.xhtml) which is Copyright © 2009, Jorge Ortiz and David Hall

## Abstract ##

A new language construct is proposed to simplify the creation of classes which provide _extension methods_ to another type.

## Description ##

The `implicit` keyword will now be allowed as an annotation on classes. Classes annotated with the `implicit` keyword are refered to as _implicit classes_.

An implicit class must have a primary constructor with *exactly* one argument in its first parameter list. It may also include an additional implicit parameter list. An implicit class must be defined in a scope where method definitions are allowed (not at the top level). An implicit class is desugared into a class and implicit method pairing, where the implciit method mimics the constructor of the class.

The generated implicit method will have the same name as the implicit class. This allows importing the implicit conversion using the name of the class, as one expects from other implicit definitions.
For example, a definition of the form:

{% highlight scala %}
implicit class RichInt(n: Int) extends Ordered[Int] {
def min(m: Int): Int = if (n <= m) n else m
...
}
{% endhighlight %}

will be transformed by the compiler as follows:

{% highlight scala %}
class RichInt(n: Int) extends Ordered[Int] {
def min(m: Int): Int = if (n <= m) n else m
...
}
implicit final def RichInt(n: Int): RichInt = new RichInt(n)
{% endhighlight %}

Annotations on `implicit` classes default to attaching to the generated class *and* the method. For example,

{% highlight scala %}
@bar
implicit class Foo(n: Int)
{% endhighlight %}

will desugar into:

{% highlight scala %}
@bar implicit def Foo(n: Int): Foo = new Foo(n)
@bar class Foo(n:Int)
{% endhighlight %}

The `annotation.target` annotations will be expanded to include a `genClass` and `method` annotation. This can be used to target annotations at just the generated class or the generated method of an implicit class. For example:

{% highlight scala %}
@(bar @genClass) implicit class Foo(n: Int)
{% endhighlight %}

will desugar into

{% highlight scala %}
implicit def Foo(n: Int): Foo = new Foo(n)
@bar class Foo(n: Int)
{% endhighlight %}


## Specification ##

No changes are required to Scala's syntax specification, as the relevant production rules already allow for implicit classes.

LocalModifier ::= ‘implicit’
BlockStat ::= {LocalModifier} TmplDef
TmplDef ::= [‘case’] ‘class’ ClassDef

The language specification (SLS 7.1) would be modified to allow the use of the implicit modifier for classes. A new section on Implicit Classes would describe the behavior of the construct.

## Consequences ##

The new syntax should not break existing code, and so remain source compatible with existing techniques.


18 changes: 13 additions & 5 deletions sips/pending/_posts/2011-10-13-uncluttering-control.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@ disqus: true
title: SIP-12 Uncluttering Scala’s syntax for control structures.
---

__Motivation__: The more Scala code I write the more I get tripped up by the need to write conditions in if-then-else expressions and other control constructs in parentheses. I normally would not advocate syntax changes at this level, except that this has been the single syntax decision that feels worse for me the longer I use it.
__Martin Odersky__

## Part 1: `if` ##
__first submitted 13 October 2011__


## Motivation ##

The more Scala code I write the more I get tripped up by the need to write conditions in if-then-else expressions and other control constructs in parentheses. I normally would not advocate syntax changes at this level, except that this has been the single syntax decision that feels worse for me the longer I use it.

## Part 1: if ##

Having to write parentheses is an unfortunate inheritance from C via Java. It makes code more cluttered than it could be. In C/C++/Java this was no big deal, but because Scala is much cleaner syntactically than these languages it starts to stick out like a sore thumb. This in particular because only one form of `if` comes with parentheses; if you use an if as a filter in a for expression or as a guard in a pattern, no parentheses are required.

Expand All @@ -28,7 +35,7 @@ So, here is the proposal (for Scala 2.10):

Once we have dealt with if, we should do the same thing with while, do-while and for.

## Part 2: `do-while` ##
## Part 2: do-while ##

do-while is easy. Simply do the following:

Expand All @@ -40,7 +47,7 @@ do-while is easy. Simply do the following:

While loops and for loops are more tricky.

## Part 3: `while` ##
## Part 3: while ##

For while loops:

Expand Down Expand Up @@ -72,7 +79,7 @@ For while loops:

4. In Scala 2.12: Drop the restriction introduced in 2.10. Conditions in a `while-do` can now be arbitrary expressions including with parentheses at the outside.

## Part 4: `for` ##
## Part 4: for ##

For-loops and for expressions can be handled similarly:

Expand Down Expand Up @@ -117,3 +124,4 @@ The new syntax removes more cases than it introduces. It also removes several ha




7 changes: 0 additions & 7 deletions sips/sip-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ type: sip
title: List of SIPs
---

### Draft SIPs ###
<ul class="post-list">
{% for post in site.categories.draft %}
<li><a href="{{ site.baseurl }}{{ post.url }}">{{ post.title }}</a> <span class="date">( {{ post.date | date: "%b %Y" }} )</span></li>
{% endfor %}
</ul>

### Completed SIPs ###
<ul class="post-list">
{% for post in site.categories.completed %}
Expand Down

0 comments on commit 9a844a6

Please sign in to comment.