Live data from Hacker News

True Scala complexity

yz.mit.edu

1–10 of 152 posts

Re: True Scala complexity

#2
I have a confession to make. I voted this article up simply based on the title. Even if it turned out to be incredible link bait (which it didn't), I'm just happy that someone out there is at least recognizing the desire to have a reasonable discussion of this issue.

Re: True Scala complexity

#3
Fantastic post. The most salient excerpt for me:

    def filterMap[B,D](f: A => Option[B])(implicit b: CanBuildFrom[?,B,D]): D
    def filterMap[B,D  Option[B])(implicit b: CanBuildFrom[?,B,D]): D
    def filterMap[B,D  Option[B])(implicit b: CanBuildFrom[?,B,D]): D
    def filterMap[B,D[B]](f: A => Option[B])(implicit b: CanBuildFrom[?,B,D[B]]): D[B]
    def filterMap[B,D[B]  Option[B])(implicit b: CanBuildFrom[?,B,D[B]]): D[B]
    def filterMap[B,D[B]  Option[B])(implicit b: CanBuildFrom[?,B,D[B]]): D[B]
    def filterMap[B,D[_]](f: A => Option[B])(implicit b: CanBuildFrom[?,B,D[B]]): D[B]
    def filterMap[B,D[_]](f: A => Option[B])(implicit b: CanBuildFrom[?,B,D[B]], ev: D[B]  Option[B])(implicit b: CanBuildFrom[?,B,D[B]], ev: D[B] => GenTraversableOnce[B]): D[B]

    ...

    > The answer to our original question? It turns out none 
    > of these are correct. In fact, *it is impossible to insert 
    > a new method that behaves like a normal collection method.* 
    > This, despite the heavy advertising of enrich my library.
Stuff like this makes think about how, despite all of the problems with using it in libraries, it's lovely that many dynamic languages can be extended in your application with little fuss.

    # Ruby.

    class Array
      def filter_map
        ...
      end
    end


    // JavaScript.

    Array.prototype.filterMap = function() {
      ...
    };

Re: True Scala complexity

#4
I think it would be great if we could replace implicits by:

1) a simple mechanism for "enrichment" (aka. retro-active extension, virtual classes)

2) functional type-level computation (as opposed to the mini-prolog engine that is implicit search + type inference).

Reducing complexity is complicated, unfortunately. We [have been|are] thinking about both of these alternative features, though.

---

ps: The following part of the article is inaccurate: "Turns out that Scala will search up to one level up the type hierarchy for a matching shape for the implicit."

Check out the "implicits without the import tax" part of http://eed3si9n.com/implicit-parameter-precedence-again. The implicit scope includes all the superclasses (and their companion objects) of all the parts of the type of the implicit value that's being resolved.

Re: True Scala complexity

#5

Fantastic post. The most salient excerpt for me: def filterMap[B,D](f: A => Option[B])(implicit b: CanBuildFrom[?,B,D]): D def filterMap[B,D Option[B])(implicit b: CanBuildFrom[?,B,D]): D def filterMap[B,D Option[B])(implicit b: CanBuildFrom[?,B,D]): D def filterMap[B,D[B]](f: A => Option[B])(implicit b: CanBuildFrom[?,B,D[B]]): D[B] def filterMap[B,D[B] Option[B])(implicit b: CanBuildFrom[?,B,D[B]]): D[B] def filter…

Common Lisp:

(defmethod filter-map (f (a array)) ...)

Re: True Scala complexity

#6
After reading a bunch of these articles and really walking away unimpressed this one is fantastic. It does a great job of showing how cryptic you can make Scala code. It also shows that the same topic on which half the article is spent explaining can be boiled down to four lines of less "Scala Like" code. As a pragmatic user of Scala I don't see why the fact that you _can_ do some amazing but cryptic things with the language is a detriment. Its like pointers in C or templates and multiple inheritance in C++. Some people say that the developer shouldn't be given such capabilities since it can lead to cryptic and possible dangerous code. I am of the opinion that the additional flexibility the features provides is nothing but a benefit and that its up to the developer/organization to make sane limits on what can be used.

Re: True Scala complexity

#7

Fantastic post. The most salient excerpt for me: def filterMap[B,D](f: A => Option[B])(implicit b: CanBuildFrom[?,B,D]): D def filterMap[B,D Option[B])(implicit b: CanBuildFrom[?,B,D]): D def filterMap[B,D Option[B])(implicit b: CanBuildFrom[?,B,D]): D def filterMap[B,D[B]](f: A => Option[B])(implicit b: CanBuildFrom[?,B,D[B]]): D[B] def filterMap[B,D[B] Option[B])(implicit b: CanBuildFrom[?,B,D[B]]): D[B] def filter…

That is a nice feature of dynamic languages, however you lose strong typing. I think the thing to take away is Scala hasn't gotten the perfect blend of these two yet. You can't make that competly generic map filtering extension yet. However you can make a less portable alternative. So you make you decision on what is more important.

Re: True Scala complexity

#8
A lot of the items the post author describes as complex you can't do at all in other languages.

"Simple things should be simple, complex things should be possible." - Alan Kay

I don't think the blog author gives particularly great examples of simple things that are made complex by the language. He simply gives examples of things that are inherently complex that scala at least makes possible.

Re: True Scala complexity

#10
post #7

Fantastic post. The most salient excerpt for me: def filterMap[B,D](f: A => Option[B])(implicit b: CanBuildFrom[?,B,D]): D def filterMap[B,D Option[B])(implicit b: CanBuildFrom[?,B,D]): D def filterMap[B,D Option[B])(implicit b: CanBuildFrom[?,B,D]): D def filterMap[B,D[B]](f: A => Option[B])(implicit b: CanBuildFrom[?,B,D[B]]): D[B] def filterMap[B,D[B] Option[B])(implicit b: CanBuildFrom[?,B,D[B]]): D[B] def filter…

That is a nice feature of dynamic languages, however you lose strong typing. I think the thing to take away is Scala hasn't gotten the perfect blend of these two yet. You can't make that competly generic map filtering extension yet. However you can make a less portable alternative. So you make you decision on what is more important.

Just to be pedantic, you lose static typing. Ruby (and Python, etc.) are strongly, dynamically typed languages.
Post reply on HN