Hacker News new | ask | show | jobs
by frowaway001 4105 days ago
Every turing-complete typesystem can take an unbounded time to compile. Scala is one of those languages with turing-complete typesystems.
1 comments

I'm not sure that's a sufficient explanation. Idris and Haskell (with extensions) also have Turing complete type systems. I've never seen either even approach performance like 1 line/minute in real code.
It's quite easy to get extremely slow type inference in expressive typing systems. This code

let f0 = fun x -> ( x, x ) in let f1 = fun y -> f0( f0 y ) in let f2 = fun y -> f1( f1 y ) in let f3 = fun y -> f2( f2 y ) in let f4 = fun y -> f3( f3 y ) in let f5 = fun y -> f4( f4 y ) in f5 ( fun z -> z );;

took at least 3 months (!) to type-infer when I ran it on my 2008 MacBook using the standard Ocaml compiler. I have not tried since. Type inference algorithms have horrendous worst-case complexity. Fortunately that worst-case complexity usually doesn't matter in practise.

I never seen 1 line/minute in Scala either, but that's not the point.

Theoretically, there is nothing stopping you from writing code which will never finish compiling if you have a Turing-complete typesystem.

I've written a lot of Scala and I don't think I've seen anything as slow as even 1 line/second. Odersky was talking about Shapeless, which is an edge case in that it is a home for all the type-heavy calculations that scalac can compile but isn't currently optimised towards.

edit: reworded for clarity

Computing a type level factorial can take more than 1 minute :)