News for hackers. Stuff that matters.
Re:Experiment: Unit testing isn't enough; You need static ty... by pimentel on Wednesday June 20, 2012 @10:04AM (#4136993)
How can you translate from python to a static language, when the code is written for the interfaces, and not types? How willl you translate a function receiving a (possibly custom) iterable, when the function doesn't care about the type, but just whether it implements a next() method?
Re:Experiment: Unit testing isn't enough; You need static ty... by pja on Wednesday June 20, 2012 @10:19AM (#4137064)
Hindley-Milner type systems to the rescue! (With a sprinkling of Haskell style type classes.)

  f :: Iterable a => a -> b
  f x = (do stuff with x...)
f is defined to be constrained to accept only on types which implement the Iterable interface (however that's defined) as it's first argument and the compiler (or interpreter) will enforce that constraint.
Re:Experiment: Unit testing isn't enough; You need static ty... by emillon on Wednesday June 20, 2012 @10:23AM (#4137084)
> Hindley-Milner type systems to the rescue!

You're implying that all type-systems derived from HM have a form of bounded polymorphism. They're not, for example OCaml does not have type classes (you could probably encode a lot into objects, though).

Re:Experiment: Unit testing isn't enough; You need static ty... by gtani on Wednesday June 20, 2012 @10:50AM (#4137238)
TYpe classes and the ML module system overlap in capabilities

http://www.cse.unsw.edu.au/~chak/papers/WC06.html

Re:Experiment: Unit testing isn't enough; You need static ty... by Dn_Ab on Wednesday June 20, 2012 @10:59AM (#4137292)
OCaml's nephew, F# does have bounded polymorphism though. Although it inherits that from the OOP side of its family.
Re:Experiment: Unit testing isn't enough; You need static ty... by carterschonwald on Wednesday June 20, 2012 @10:28AM (#4137114)
False, ocaml has type classes now! (or maybe I'm thinking of coq)
Re:Experiment: Unit testing isn't enough; You need static ty... by pja on Wednesday June 20, 2012 @10:40AM (#4137182)
I don't think so: If you want the equivalent of Haskell type classes in OCaml then you have to either use a functors or some sort of class IIRC. I'm sure Oleg will have done something though.

I believe they're experimental in Coq.

Re:Experiment: Unit testing isn't enough; You need static ty... by carterschonwald on Wednesday June 20, 2012 @11:45PM (#4140455)
yup, you're right, you got to use functors or go home.

Yeup, some folks did show the functors + modules \equiv type classes in some sense, for system F or a variant thereof. Theres also an oleg approach too I think.

Re:Experiment: Unit testing isn't enough; You need static ty... by sbmassey on Wednesday June 20, 2012 @10:13AM (#4137039)
Haskell type classes are sufficiently flexible to represent things like 'does this type have a next method' without having to instrument the actual type.
Re:Experiment: Unit testing isn't enough; You need static ty... by pimentel on Wednesday June 20, 2012 @10:33AM (#4137137)
But could that kind of type system be considered similar to the usual Java-like little-flexible static typing? I think I would prefer a static vs dynamic implemented as Java vs Python (since those are usually the subjects on every one of these discussions)
Re:Experiment: Unit testing isn't enough; You need static ty... by hythloday on Wednesday June 20, 2012 @10:44AM (#4137200)
It's identical, conceptually. A type class can be thought of as a degenerate kind of Adapter pattern.
Re:Experiment: Unit testing isn't enough; You need static ty... by ufo on Wednesday June 20, 2012 @05:17PM (#4139161)
ALthough the name is confusing type classes are very much like interfaces in Java: you define a set of operations that you want and then instantiate concrete types to that interface.

The major differences between type classes and interfaces are: * In Java interfaces the interfaced type is restricted to the first argument (the this). In Haskell interfaces the interfaced type can also appear on return values and arguments. * In Java you need to decide what interfaces to implement when you create your class. Haskell allows interfaces to be implemented for previously existing types. * Java allows for subtyping. You can turn a monomorphic program into a polymorphic one just by creating subclasses while in Haskell you would need to rewrite your code to be explicitly polymorphic.

Re:Experiment: Unit testing isn't enough; You need static ty... by troels on Wednesday June 20, 2012 @10:21AM (#4137075)
There's a difference between the implementation type and the protocol type. Or as Java calls them - Classes and Interfaces. Unfortunately most classical OO language collate the two, causing much confusion.
Re:Experiment: Unit testing isn't enough; You need static ty... by Symmetry on Wednesday June 20, 2012 @10:46AM (#4137212)
Haskell's typeclasses are very close to this, but even closer is Go. You just define and interface and the functions that require it, and the compiler goes off and check's by itself whether the type you're passing in satifies the interface - no need for you to annotate it yourself. You lose Haskell's nifty "deriving" feature, but it's even closer to Python's duck typing with compile time checks.
Re:Experiment: Unit testing isn't enough; You need static ty... by dons on Wednesday June 20, 2012 @10:18AM (#4137062)
> the function doesn't care about the type, but just whether it implements a next() method?

You're describing an "existential" type.

Re:Experiment: Unit testing isn't enough; You need static ty... by dllthomas on Wednesday June 20, 2012 @12:43PM (#4137782)
... or a typeclass.
Re:Experiment: Unit testing isn't enough; You need static ty... by JustinJ70s on Wednesday June 20, 2012 @04:05PM (#4138854)
Scala's type system can handle this as it support type safe duck typing.