Typelevel quicksort in Scala
jto.github.io
jto.github.io
This makes me wonder if 'values' can be though of as just subtypes of their types. '5' extends 'Number', say. Is this how it's interpreted in the fully-functional paradigm?
If you have
def fn(x: Int) : Int
then 'Int' is the type of all Ints, and you have to provide a specific int - which is a subtype of Int, but you could imagine there being a subtype between 'Int' and '5', like:
5 <: intermediateType <: Int
So in order to 'invoke' a function you have to provide a subtype that reduces it to one value, at the level of 5, not just any subtype of int. Meaning that something about '5' makes it a special kind of subtype that can actually be used to execute the function. Maybe that's what we mean by 'value'. I don't know.
I do find the idea that fn(5) is a subtype of fn(x: Int) to be cute.
And that
def foo(x: Int): Int = fn(x)
has the 'subtype'
foo(5): fn(5)
seems suggestive.
The idea of a value being a type is the nature of "dependently typed" languages. However, they do it the other way around: types are merely values. This is very similar to what you're saying except DT languages would not have that
5 : 5
Instead, we introduce the idea of a singleton type. It works like this: for any type A and any value (x : A), we have a type (Sing A x) with exactly one value, (TheSing x : Sing A x).The other thing to keep in mind is that subtyping is kind of a rocky place to lay your type semantics. This is rough because most people are used to subtyping in their types. Instead, we note that whenever we have that (A :> B) then we have a function (A -> B) which is injective (really, an "epimorphism"). This broaden's our view to consider any injective function between types instead of merely some subtyping relation. Immediately it ought to be clear that (a) this is intractable automatically and (b) it's far more rich. Then it turns out that subtyping itself is fairly intractable (which subtypes are the right ones? there are many types intermediate between (Sing Integer 5) and (Integer)).
So throw away automatic subsumption and require explicit coercions. This is workable and indeed in use today.
http://people.tamu.edu/~hiraditya/index_files/ProgLang_Prese...
You do exchange a typing judgment for a subtyping one.
I feel like we haven't really looked at subtyping enough. It might not be so hard as it is different, that our existing type systems simply aren't suited to it but we could come up with subtype systems that are.
Personally, I try to avoid subtyping where possible; I usually end up getting weird contradictions.
And really there is no alternative - once you've used higher-kinded types there's no going back. Some organizations make the switch to Haskell, but that's not an option in many environments. Other than that, if you want higher-kinded types there's nothing that's remotely as mature as Scala out there.
I can't speak to "fundamental issues with the language" because I haven't found any.
I disagree. Once you learn to use partially applied higher-order functions, they end up being useful everywhere. I'm using them right now in Scala for my day job, and my code is not particularly fancy.
> The amount of times where defining a partially applied higher-order function is the best way to solve a problem is nonzero, but still really really low.
I was with you until this. Using partial application doesn't create monsters, and in fact is rather easy to follow and understand (assuming you know what partial application is, of course).
There are however, features of Scala that can be abused to create monsters, the most obvious of which is implicit conversions. An extremely useful feature, but can cause a mess if you're not careful. And even with those, it's still entirely static, and your IDE can highlight which ones happened where, as opposed to something like Ruby, where you can update classes at runtime.
Not sure about Scala, but I find partially applied higher order functions to frequently be the best choice in Haskell code.
And you're not exactly contradicting me. They are an "advanced" feature partly because they're not found in (many) other languages.
Do companies that have adopted Scala really value higher-kinded typing that much?
I've gotten used to handling concurrency as a monad, for example, and honestly dread the time when I have to manually deal with manual synchronisation again.
An added benefit: due to the scarcity, lots of Scala shops are open to remote developers. I abhor the idea of moving back to the Bay Area so that's important to me.
Having said that, what evidence do you have that Twitter is backing away from Scala? What are they supposed to be replacing it with? My own experience is that mainstream jobs in my country are very slowly and timidly starting to adopt Scala, and only in the most controlled fashion, as "just a better Java".
You don't have to do this if you're already using a hybrid sort to prevent Quicksort's worst case, like introsort or (shameless self promotion) pdqsort (https://github.com/orlp/pdqsort).
I haven't run the math, but I don't believe introsort fixes this. It's a constant-factor optimization.