after 10+ years of using statically typed languages and not having a clue why anyone would use dynamic types because all you get is code you can't maintain, i finally understood one big advantage of dynamic typing (thanks to clojure which was an eye opener).
in java, you force the caller of a method to use an instance of type X - even if you only need a small fraction of X's methods or fields. if you have a big class that can do a lot or provides a lot of information, that class will appear virtually anywhere even though only parts of it are accessed.
in clojure, instead of "i need type x" you say "i need something that is compatible to type x" where type x might never be explicily declared and only exists in the programmers mind and at runtime.
scala has structural types for that, but clojure's destructuring is more powerful. it works on maps, arrays and classes and i won't have to worry about what is given to my function.
the absense of a type system also makes things like
createmap(key, value, key2, value2... keyN, valueN) possible. no typesystem i know of can be told to make sure the number of parameters is _ % 2 == 0. of course you can always cheat by using tuples or method overloading for every possible parameter count up to 2*n but the most simple solution in this case is to just skip the static types.
so i wonder, what are the improvements planned for the next scala releases?
There is a type system you know of that is capable of that. It is called
"Scala" and since you are given greater guarantees of correctness, the
ability to go even higher in abstraction is much more tractable.
Furthermore, not only is this possible, but everything you describe, and
more, also has been implemented.
The most "simple" solution is not to "just skip the static types."
I especially love how "simple" has become a synonym for "this is the
current limit of my capacity."
Don't forget though, Scala is not simple; it is complex.
Do I have to keep taking this stuff seriously?
--
Tony Morris
http://tmorris.net/
-------- Original-Nachricht --------
> Datum: Wed, 16 Nov 2011 21:53:15 +1000
> Von: Tony Morris <tonym...@gmail.com>
> An: scala-...@googlegroups.com
> Betreff: Re: [scala-debate] planned type system enhancements
that is actually pretty close to my definition of simple
hi there,
after 10+ years of using statically typed languages and not having a clue why anyone would use dynamic types because all you get is code you can't maintain, i finally understood one big advantage of dynamic typing (thanks to clojure which was an eye opener).
in java, you force the caller of a method to use an instance of type X - even if you only need a small fraction of X's methods or fields. if you have a big class that can do a lot or provides a lot of information, that class will appear virtually anywhere even though only parts of it are accessed.
in clojure, instead of "i need type x" you say "i need something that is compatible to type x" where type x might never be explicily declared and only exists in the programmers mind and at runtime.
scala has structural types for that, but clojure's destructuring is more powerful. it works on maps, arrays and classes and i won't have to worry about what is given to my function.
the absense of a type system also makes things like
createmap(key, value, key2, value2... keyN, valueN) possible. no typesystem i know of can be told to make sure the number of parameters is _ % 2 == 0. of course you can always cheat by using tuples
or method overloading for every possible parameter count up to 2*n but the most simple solution in this case is to just skip the static types.
so i wonder, what are the improvements planned for the next scala releases?
in clojure, instead of "i need type x" you say "i need something that is compatible to type x" where type x might never be explicily declared and only exists in the programmers mind and at runtime.
scala has structural types for that, but clojure's destructuring is more powerful. it works on maps, arrays and classes and i won't have to worry about what is given to my function.
the absense of a type system also makes things like
createmap(key, value, key2, value2... keyN, valueN) possible. no typesystem i know of can be told to make sure the number of parameters is _ % 2 == 0. of course you can always cheat by using tuples or method overloading for every possible parameter count up to 2*n but the most simple solution in this case is to just skip the static types.
No, there would be also the possibility to use an HList and an implicit
evidence that the HList of the structure you want (this evidence will
also carry a way to destructure the HList). The implicit search can be
compared to a Prolog interpreter, and the divisibility by 2 is
definitely something it can do.
Furthermore, Scala's type system itself is Turing-complete. You can
encode whatever is computable in types, without even using implicits.
Refer to
<http://apocalisp.wordpress.com/2011/01/13/simple-ski-combinator-calculus-in-scalas-type-system/>
for more information.
Furthermore, Scala's type system itself is Turing-complete. You can
encode whatever is computable in types, without even using implicits.
Refer to
<http://apocalisp.wordpress.com/2011/01/13/simple-ski-combinator-calculus-in-scalas-type-system/>
for more information.
What exactly do you mean by "loophole"? Because `X#ap` is replaced by
the type which it stands for and not left as it is?
> On Wed, Nov 16, 2011 at 12:47 PM, Dennis Haupt <h-s...@gmx.de> wrote:
no of course not, but you don't say "even number of parameters" to the type system, you're saying "variable number of tuples having 2 attributes"
you can express this easily in scala, but only with the help of other constructs like a tuple, implicit conversions and other helpers.
what if i make up the following rule:
the first parameter is an instance of type x. the next n parameters are optional parameters and the next one is mandatory and of type z.
the call would look like this in clojure
(magic first op1 op2 op3 last
first2 op1b op2b last2
....)
in scala, the call would look like:
magic((first,List(op1,op2,op3), last), ...)
i need to put the parameters into a structure before making the call. in clojure or a magic static type system more powerful than that of scala, i can just apply them without preparing a structure at every call site. the called function would take care of that, or the magic compiler that i have not seen yet.
>
>
> >
> > so i wonder, what are the improvements planned for the next scala
> releases?
> >
> >
>
>
> --
> Viktor Klang
>
> Akka Tech Lead
> Typesafe <http://www.typesafe.com/> - Enterprise-Grade Scala from the
> Experts
>
> Twitter: @viktorklang
you can express this easily in scala, but only with the help of other constructs like a tuple, implicit conversions and other helpers.
what if i make up the following rule:
the first parameter is an instance of type x. the next n parameters are optional parameters and the next one is mandatory and of type z.
the call would look like this in clojure
(magic first op1 op2 op3 last
first2 op1b op2b last2
....)
in scala, the call would look like:
magic((first,List(op1,op2,op3), last), ...)
i need to put the parameters into a structure before making the call. in clojure or a magic static type system more powerful than that of scala, i can just apply them without preparing a structure at every call site. the called function would take care of that, or the magic compiler that i have not seen yet.
> Typesafe <http://www.typesafe.com/> - Enterprise-Grade Scala from the
>
>
> >
> > so i wonder, what are the improvements planned for the next scala
> releases?
> >
> >
>
>
> --
> Viktor Klang
>
> Akka Tech Lead
> Experts
>
> Twitter: @viktorklang
-------- Original-Nachricht --------
> Datum: Wed, 16 Nov 2011 14:14:28 +0100
> Von: Adriaan Moors <adriaa...@epfl.ch>
> An: Dennis Haupt <h-s...@gmx.de>
> CC: scala-...@googlegroups.com
> Betreff: Re: [scala-debate] planned type system enhancements
> >
> > in clojure, instead of "i need type x" you say "i need something that is
> > compatible to type x" where type x might never be explicily declared and
> > only exists in the programmers mind and at runtime.
> >
> I don't follow. I'm guessing you don't really say "i need something that
> is
> compatible to type x", you just *hope *it will be.
you "say" it at runtime. as i said, there is no static type system which i know of that can make everything typesafe what i can do with dynamic typing.
-------- Original-Nachricht --------
> Datum: Wed, 16 Nov 2011 15:21:41 +0100
it's not the same. the scala call *would*, if possible, be:
magic("foo",1,2,3,4,"bar","foo2",5,6,"bar2")
and it would be the job of the compiler to figure out that the numbers belong together.
as i said, there is no static type system which i know of that can make everything typesafe what i can do with dynamic typing.
-------- Original-Nachricht --------
> Datum: Wed, 16 Nov 2011 15:26:48 +0100
> Von: Adriaan Moors <adriaa...@epfl.ch>
> An: Dennis Haupt <h-s...@gmx.de>
> CC: scala-...@googlegroups.com
> Betreff: Re: [scala-debate] planned type system enhancements
> On Wed, Nov 16, 2011 at 3:22 PM, Dennis Haupt <h-s...@gmx.de> wrote:
scala> def f(x:Any { def yell : String }) = x.yell + x.yell
f: (x: Any{def yell: String})java.lang.String
scala> class Dog { def yell = "woof"; def size = 4 }
defined class Dog
scala> f(new Dog())
res1: java.lang.String = woofwoof
See, f accepts any type that has *at least* yell. It doesn't care that
Dog has also size or that it is a dog.
Paul
-------- Original-Nachricht --------
> Datum: Wed, 16 Nov 2011 16:53:18 +0100
> Von: Paul Brauner <polu...@gmail.com>
> An: Dennis Haupt <h-s...@gmx.de>
> CC: scala-...@googlegroups.com
> Betreff: Re: [scala-debate] planned type system enhancements
> I think what you want is structural subtyping (or "static duck
Paul
What about "pimping" the existing type alias construct to support
specialization:
type X[T] = T
type X[T >: Int <: Int] = Boolean
type X[T >: String <: String] = Int
Kinda similar to Haskell type families and C++ template specialization.
It would allow a trivial definition of a type level equality check:
type Eq[T, U] = False
type Eq[T >: U <: U, U] = True
/Jesper Nordenberg
Let me know if I can help. I'd expect others who'd be interested too.
Perhaps you could put your current thoughts in writing and we could all
do some thinking about it.
This is a well-documented contention in type theory.
Roughly, the purpose of a static type system is to disallow incorrect
programs while allowing correct programs, but it cannot achieve this
perfectly, so trade-offs must be made. So in order to keep the question
interesting, we must alter it by appealing to practicality.
What correct programs does our static type system disallow? Furthermore,
what are the practical implications of these programs being disallowed
and are they worth the trade-off for the correctness guarantees provided
for the other cases? So far, you have only demonstrated correct programs
that our type system does allow -- how uninteresting. As an interesting
aside, try answering these questions in the context of Java's type
system -- yeah exactly, now you know why it's a bit of a joke.
To demonstrate your point, what you'd need to do is provide a correct
program that the type system disallows, is a relatively common use-case
(this is a bit wishy-washy) and also demonstrate what is required in
order to actually express an equivalent of that program (e.g. extra
labour). So far, you're not even close to doing this.
Sound simple enough? Or was that complex enough -- I can never remember.
IIRC the regular type systems used in CDuce and XDuce can express this
kind of types, because they use regular expressions over types.
> so i wonder, what are the improvements planned for the next scala releases?
Best regards,
Daniel Yokomizo
Yes, exactly. See for example
<http://www.cis.upenn.edu/~bcpierce/papers/xduce-slides.ps> for details.
However, it turned out to be not very practical, because the type
checker needs exponential time in the worst case.
Curious... why? Regular expressions can be evaluated in linear time,
though most implementations fail in this regard just to "optimize" for
the common case, and, of course, to allow back references -- which are
not allowable in a regular expression.
--
Daniel C. Sobral
I travel to the future all the time.
That's what I thought first, too; if you refer to regular expressions as
defined by "accepted by a finite automaton". Inclusion testing would be
then to simply take two finite automata, make a product automaton with
some end states flipped around and check emptiness.
However, it seems that those regular expression types need tree
automata, mainly because they allow recursion (?). That seems to fall
out of the scope of a normal finite automaton, but not to the degree
where a context-free grammar is needed (where inclusion is undecidable).
What about "pimping" the existing type alias construct to support specialization:
type X[T] = T
type X[T >: Int <: Int] = Boolean
type X[T >: String <: String] = Int
Kinda similar to Haskell type families and C++ template specialization.
It would allow a trivial definition of a type level equality check:
type Eq[T, U] = False
type Eq[T >: U <: U, U] = True
What correct programs does our static type system disallow? Furthermore,
what are the practical implications of these programs being disallowed
and are they worth the trade-off for the correctness guarantees provided
for the other cases? So far, you have only demonstrated correct programs
that our type system does allow -- how uninteresting. As an interesting
aside, try answering these questions in the context of Java's type
system -- yeah exactly, now you know why it's a bit of a joke.
-------- Original-Nachricht --------
> Datum: Thu, 17 Nov 2011 10:51:35 +0000
> Von: "nicola...@gmail.com" <nicola...@gmail.com>
> An: tmo...@tmorris.net
> CC: scala-...@googlegroups.com
> Betreff: Re: [scala-debate] planned type system enhancements
> >
> >
> > What correct programs does our static type system disallow? Furthermore,
> > what are the practical implications of these programs being disallowed
> > and are they worth the trade-off for the correctness guarantees provided
> > for the other cases? So far, you have only demonstrated correct programs
> > that our type system does allow -- how uninteresting. As an interesting
> > aside, try answering these questions in the context of Java's type
> > system -- yeah exactly, now you know why it's a bit of a joke.
> >
> >
> I would like to complete that by another important question:
> how much noise does the static typing adds to the program?
>
> I think dynamically typed language users would be happy to use a
> statically
> typed language that can type check all the programs they want to write
> without too
> much noise.
more precisely, how often do you have to repeat that noise? once at the method declaration? ok then. at each call site? bad.
+1
Although I'd say this is not exactly the #1 priority. Still, we would be
very happy to see a draft of such a feature whenever you're ready.
no of course not, but you don't say "even number of parameters" to the type system, you're saying "variable number of tuples having 2 attributes"
you can express this easily in scala, but only with the help of other constructs like a tuple, implicit conversions and other helpers.
what if i make up the following rule:
the first parameter is an instance of type x. the next n parameters are optional parameters and the next one is mandatory and of type z.
the call would look like this in clojure
(magic first op1 op2 op3 last
first2 op1b op2b last2
....)
in scala, the call would look like:
magic((first,List(op1,op2,op3), last), ...)
i need to put the parameters into a structure before making the call. in clojure or a magic static type system more powerful than that of scala, i can just apply them without preparing a structure at every call site. the called function would take care of that, or the magic compiler that i have not seen yet.