Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I hope it's not a "suicide note", but I can see your point. You hit on what is at the same time both a strength and a problem of Scala: its <strong>extensibility</strong>. This lets us implement most major functionality in libraries. In some other languages, sequences with something like <code>map</code> or <code>collect</code> would be built in, and nobody has to see all the hoops the compiler has to go through to make them work smoothly. In Scala, it's all in a library, and therefore out in the open.</p> <p>In fact the functionality of <code>map</code> that's supported by its complicated type is pretty advanced. Consider this:</p> <pre><code>scala&gt; import collection.immutable.BitSet import collection.immutable.BitSet scala&gt; val bits = BitSet(1, 2, 3) bits: scala.collection.immutable.BitSet = BitSet(1, 2, 3) scala&gt; val shifted = bits map { _ + 1 } shifted: scala.collection.immutable.BitSet = BitSet(2, 3, 4) scala&gt; val displayed = bits map { _.toString + "!" } displayed: scala.collection.immutable.Set[java.lang.String] = Set(1!, 2!, 3!) </code></pre> <p>See how you always get the best possible type? If you map <code>Int</code>s to <code>Int</code>s you get again a <code>BitSet</code>, but if you map <code>Int</code>s to <code>String</code>s, you get a general <code>Set</code>. Both the static type and the runtime representation of map's result depend on the result type of the function that's passed to it. And this works even if the set is empty, so the function is never applied! As far as I know there is no other collection framework with an equivalent functionality. Yet from a user perspective this is how things are <em>supposed</em> to work.</p> <p>The problem we have is that all the clever technology that makes this happen leaks into the type signatures which become large and scary. But maybe a user should not be shown by default the full type signature of <code>map</code>? How about if she looked up <code>map</code> in <code>BitSet</code> she got:</p> <pre><code>map(f: Int =&gt; Int): BitSet (click here for more general type) </code></pre> <p>The docs would not lie in that case, because from a user perspective indeed map has the type <code>(Int =&gt; Int) =&gt; BitSet</code>. But <code>map</code> also has a more general type which can be inspected by clicking on another link.</p> <p>We have not yet implemented functionality like this in our tools. But I believe we need to do this, to avoid scaring people off and to give more useful info. With tools like that, hopefully smart frameworks and libraries will not become suicide notes. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload