What statically typed languages ​​are similar to Python?

Python is the nicest language I know about right now, but static typing is a big advantage due to automatic completion (although limited support for dynamic languages ​​is nothing compared to what is supported in static). I am curious if there are any languages ​​that are trying to add the benefits of Python to a statically typed language. In particular, I am interested in languages ​​with features such as:

  • Syntax support: for example, for dictionaries, understanding the array
  • Functions: keyword arguments, closures, tuple / multiple return values
  • Change runtime / create classes
  • Avoiding class specifications everywhere (in Python, this is due to duck text input, although type inference will work better in a statically typed language)
  • Support for metaprogramming: this is achieved in Python through reflection, annotations, and metaclasses

Are there any statically typed languages ​​with a significant number of these functions?

+41
python programming-languages
Feb 15 '10 at 9:17
source share
10 answers

Boo is a statically typed language for the Common Language Infrastructure (e.g., the Microsoft.NET platform). The syntax is very inspired by Python, and hashes / lists / array are part of the syntax:

i = 5 if i > 5: print "i is greater than 5." else: print "i is less than or equal to 5." hash = {'a': 1, 'b': 2, 'monkey': 3, 42: 'the answer'} print hash['a'] print hash[42] for item in hash: print item.Key, '=>', item.Value 
+35
Feb 15 '10 at 9:20
source share

Cobra is a statically typed language for the CLR (like Boo). On the web page:

Cobra is a general-purpose programming language with:

  - a clean, high-level syntax - static and dynamic binding - first class support for unit tests and contracts - compiled performance with scripting conveniences - lambdas and closures - extensions and mixins - ...and more 
 Sample code: """ This is a doc string for the whole module. """ class Person """ This is a class declaration. """ var _name as String # declare an object variable. every instance of Person will have a name var _age as int cue init(name as String, age as int) _name = name _age = age def sayHello # This is a method # In strings, anything in brackets ([]) is evaluated as an expression, # converted to a string and substituted into the string: print 'Hello. My name is [_name] and I am [_age].' def add(i as int, j as int) as int """ Adds the two arguments and returns their sum. """ return i + j 
+13
Feb 15 2018-10-15
source share

Although it is not object oriented, Haskell offers a significant number of functions that interest you:

  • Syntax support for list recognition, plus the do notation for a large number of sequencing / linking constructs. (Syntax support for dictionaries is limited to pairs lists, e.g.

     dict = ofElements [("Sputnik", 1957), ("Apollo", 1969), ("Challenger", 1988)] 
  • Functions support full closure and multiple return values ​​using tuple types. Keyword arguments are not supported, but the powerful function of "implicit arguments" can sometimes be replaced.

  • There is no modification of classes, types or objects at run time.

  • Avoiding specific classes / types worldwide through type inference.

  • Metaprogramming using the Haskell pattern.

In addition, so that you feel at home, Haskell has a significant indentation!

I really think that Haskell has a completely different feeling from Python in general, but this is primarily due to the extremely powerful static type system. If you're interested in a static typed language, Haskell is one of the most ambitious ones right now.

+9
Feb 15 '10 at 22:53
source share

This may not meet all your needs, but check out Boo - A Language Open to the CLI

If you do, I highly recommend DSL in Boo: Domain Languages ​​in .NET , which, in addition to the DSL aspects, covers Boo syntax in a very nice application and a lot of metaprogramming.

In addition, tutorials are a great resource.

+8
Feb 15 '10 at 9:20
source share

Go programming language. I saw some similar paradigm.

+6
Feb 15 '10 at 22:56
source share

Rpython is a subset of Python that is statically typed.

+4
Dec 19 '12 at 19:08
source share

The D programming language is a statically typed, originally compiled language that has some essential features inspired by Python.

Arrays and associative arrays are built into the language. There are no concepts on lists, but the std.range and std.algorithm libraries fill in most of this void. For example, here you can summarize all even numbers from 0 to 100 in D:

 auto result = reduce!"a + b"( filter!"a % 2 == 0"( iota(0, 100) ) ); 

There are still no arguments with keywords, but closed. Tuples are supported, but not unpacked automatically.

In D, you avoid specifying classes (and types in general) everywhere with the auto keyword and with templates. For example, here is a generic code to find the product of an array of any number type:

 // The return type of product() is inferred. auto product(T)(T[] array) { T ret = 1; foreach(num; array) { // typeof(num) is inferred. ret *= num; } return ret; } 
Metaprogramming Support

D consists of an introspection of compilation time (for example, you can iterate over fields of a class or structure at compile time), information about the type of runtime, and patterns that are actually designed for metaprogramming outside of simple generics. For example, here's how to write a generic function that generates a default comparison operation for two structures, which is useful if you need arbitrary full ordering for something like a binary tree:

 /**Returns -1 if lhs < rhs, 0 if lhs == rhs, 1 if lhs > rhs.*/ int compareStructs(T)(T lhs, T rhs) { foreach(tupleIndex, value; lhs.tupleof) { if(value < rhs.tupeof[tupleIndex]) { return -1; } else if(value > rhs.tupleof[tupleIndex]) { return 1; } } return 0; } 
+2
Feb 15 '10 at 19:39
source share

Autocomplete is still possible in a dynamically typed language; nothing prevents the IDE from performing output or type checking, even if the language implementation does not.

+1
Feb 15 '10 at 9:49
source share

If autocomplete is what you're looking for, then you might want to use Python and use a great IDE.

Try PyCharm: http://www.jetbrains.com/pycharm/index.html

If you don’t encode some extremely dynamic materials (which you probably cannot do in a static language, anyway), it will keep up with the code and give you the completion, refactoring, and all the other useful effects that we are used to in static typed languages.

You can specify typehints for the IDE where you really need it:

 def foo(bar): if 0: bar = Bar() # "if 0" will be removed from the bytecode automatically by python bar. # will now autocomplete 
+1
Feb 15 '10 at 9:52
source share

I think Eric and PyScripter have good autocomplete on Windows, but maybe not as good as PyTools for Visual Studio (Express).

For static input in Python, I would use Cython: http://docs.cython.org/src/quickstart/cythonize.html

0
Oct. 16 '11 at 23:13
source share



All Articles