What statically typed languages are similar to Python?
Although it is not object-oriented, Haskell offers a significant number of the features that interest you:
Syntax support for list comprehensions, plus
do
notation for a wide variety of sequencing/binding constructs. (Syntax support for dictionaries is limited to lists of pairs, e.g,dict = ofElements [("Sputnik", 1957), ("Apollo", 1969), ("Challenger", 1988)]
Functions support full closures and multiple return values using tuple types. Keyword arguments are not supported but a powerful feature of "implicit arguments" can sometimes substitute.
No runtime modification of classes, types or objects.
Avoidance of specificying classes/types everywhere through type inference.
Metaprogramming using Template Haskell.
Also, just so you will feel at home, Haskell has significant indentation!
I actually think Haskell has quite a different feel from Python overall, but that is primarily because of the extremely powerful static type system. If you are interested in trying a statically typed language, Haskell is one of the most ambitious ones out there right now.
Cobra is a statically typed language for the CLR (as Boo). From its 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
Boo is a statically typed language for the Common Language Infrastructure (aka. the Microsoft .NET platform). The syntax is highly 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
It may not match all your needs, but have a look at Boo - The wristfriendly language for the CLI
If you do, I highly recommend DSLs in Boo: Domain-Specific Languages in .NET which apart from the DSL aspects, covers Boo syntax in a very nice appendix and a lot of meta-programming.
Furthermore the tutorials are a great resource.