3

I can think of two major reasons as to why Cardano chose a strongly-typed functional language for it's Blockchain:

  1. Strongly-typed - because as the capabilities of the Blockchain and scripts become more powerfull, type safety is a must-have to ensure determinism and security.
  2. Functional - because it adapts very well with the UTXO design.

So my question is doesn't Haskell already fit the bill? Why is the Plutus library, its intermediary representations and Plutus Core even needed?

1
  • 2
    1. Haskell is a lazy language, this allows for infinite data structures. Onchain this is a hazard since it opens the door to attacks, you want a strict language to keep things deterministic. For more hava a look at youtu.be/xWlUrq0y4JY?t=790
    – Fermat
    Commented Jul 15, 2022 at 8:04

2 Answers 2

8

There are many reasons. For example:

  • You need tooling for the communication between the on-chain and the off-chain code and many other tasks.
  • You need tooling that generates code where the on-chain code is quite specific. You can't use the regular machine code that the Haskell compiler gives you and run it on the blockchain.
  • With a language so versatile as Haskell, you can write extremely complex code. This is great in some settings, but with smart contracts, it increases the chances of error.

Those are some of the issues that you don't have to deal with because of Plutus:

  • Plutus provides a lot of infrastructure developers would have to create themselves if they'd just use naked Haskell. So it saves effort and makes it easier to develop smart contracts.
  • It limits the library interfaces available to developers making it straightforward for them to write secure and performant code.
  • In the blockchain, you want a code format that is designed to be easy to reason about, closely implements the mathematical specification, and allows you to be confident that it's correctly implemented. That's why we have Plutus Core.

Sources:

2
  • 1
    awesome answer, I would also cite the need for reduced set of instructions so that it is possible to reduce the effective size of the serialized smart contract on-chain Commented Jul 15, 2022 at 18:09
  • Do you have a source for that?
    – Fermat
    Commented Jul 15, 2022 at 18:48
1

Eager vs Lazy Evaluation

Haskell is used for programs that require a high degree of formal verification. That's why both off-chain and on-chain code for Cardano is written in Haskell. Plutus is visually similar to Haskell, but unlike Haskell, the language is Eagerly Evaluated.

4 widely available Haskell's implementations – GHC, NHC98, Hugs98, and HBC compilers – all use lazy evaluation. That was the core reason to launch a new language for smart contracts' developers.

The second reason is: on Plutus platform, GHC compiles the off-chain code, while the Plutus compiler compiles the on-chain code. Third reason is quite obvious: the complexity of Plutus is much lower than that of Haskell.

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.