4 ms·
My dream back in 2008 or so was a language with smart enough type inference and probably some kind of gradual typing that allowed you to bridge the gap from sta
by atombender 8y ago
My dream back in 2008 or so was a language with smart enough type inference and probably some kind of gradual typing that allowed you to bridge the gap from static and dynamic typing -- dynamic for the prototyping, REPL, quick scripts and very high level code, but as you go down the layers into lower-level, more performance-sensitive code you could add more and more typing and machine-specific hacks.
Type inference might got one halfway there, but it would work best at the call site -- the type of variables could be inferred from return values and from literals and so on. But you'd still want to define a function as basically returning "Any". This means a caller wouldn't have a type for the return value, and so if you want to do "fileName := funcReturningAny(); openFile(fileName)" and openFile() was defined only for a string argument, the compiler would have to generate a runtime check at the call site to assert the type fileName as being a strong. This the call site is penalized for being typeless, but the statically typed code wouldn't be.
I suspect this would work pretty well. You can start out with no types, and you'd be able to add types as you go, slowly tightening the screws on your program. Generics, traits and other modern abstractions would still be available, though some of those features would start to become unavailable or awkward to use with any code not sufficiently tightened with types.
I don't know of any language that does anything like this, although I suppose TypeScript is pretty close.
- url00 8y agoDynamic in C# is pretty much what you describe!
- megaman22 8y agoPretty much nobody does this, but you certainly could. I'm not sure that all that DLR work that was put in gets a ton of real usage, particularly with how C# has grown language features since then.
- annywhey 8y agoBasically have already lived this dream with Haxe. However the cross-platform tooling side of Haxe has historically been the fly in the ointment since it sits above the "real runtime" of whatever you targeted, creating all sorts of bits of friction. And it doesn't cross over into "systems" stuff - it's always within a GC'd environment.
- tadzik_ 8y agoSounds like what Perl 6 does :) You can add optional type signatures, and you get compile-time checks disallowing impossible usages of these: > sub takes-string(Str $foo) { } sub takes-string (Str $foo) { #`(Sub|94327719210888) ... } > takes-string(5); say "Hi!" ===SORRY!=== Error while compiling: Calling takes-string(Int) will never work with declared signature (Str $foo) ------> <BOL>⏏takes-string(5); say "Hi!"