|
I mean, the multiple-ways-to-do-things bit is possible in any language. Even Python, with its guiding principle that 'there's only one way to do it', would allow you to do it in different ways: def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n-1)
def factorial(n):
return 1 if n == 0 else n * factorial(n-1)
def factorial(n):
return eval('*'.join(map(str, range(1, n+1))))
def factorial(n):
return reduce(lambda x, y: x * y, range(1, n+1))
def factorial(n):
def facts():
n, r = 1, 1
while True:
r, n = n*r, n+1
yield r
return next(islice(facts(), n-1, None))
The difference is: historically, Haskell was an experimental language, a test-bed for trying out new and weird ideas, which meant that experimentation with style has been pretty normal thing. Haskell "culture" encouraged being clever, because that's how you found new, interesting ideas. On the other hand, Python doesn't have that legacy: most of the implementations above are non-idiomatic because they're too clever.So yes, you can write things lots of ways in Haskell. But, if you had production code in Haskell, you wouldn't try to be clever, in the same way that you wouldn't (or shouldn't) try to be clever in production code in Python. You'd write simple, straightforward code, just like fact n = prod [1..n]
|
It doesn't mean that the language design is going to somehow ensure there's only one way (even only one idiomatic way) for users to implement any particular algorithm. It doesn't mean everyone has to use the same web framework. It's really not prescriptive, except for Python itself.