15

Is there a technical limitation preventing functional programming on the EVM? For instance the cost of computation?

I have heard that FP is "too costly". Is that correct? If it is, why?

Because "functional programming" is a broad category, this is a bit of a broad question. But knowing if FP is possible could inspire people to explore either creating a functional language or even integrating some functional programming concepts into Solidity.

1 Answer 1

12

There are some aspects of functional programming that can cause slowdowns on common hardware and VMs; for a discussion see Wikipedia's section on efficiency issues. This arises because some mutable data types, like arrays, have natural mappings to hardware, where equivalent immutable constructs in functional languages don't.

Still, with a good compiler, these slowdowns can be minimal, and it's not clear that the typical workload of an EVM contract is one that would suffer overly from the issue. In my opinion, at least, it would be entirely practical to develop a functional language for the EVM.

The only thing preventing this, really, is that compilers for functional languages tend to be more difficult to write well: they require good knowledge of compiler theory and design in order to produce efficient code, and the computation model they use is significantly different from what they're being asked to produce code for, making more work for the compiler.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.