{"id":"3lSUB3wuAyk","title":"Lesson 2: Functional Language Overview","description":"00:24 Functional Programming\n01:21 Immutability\n02:20 Composibility\n03:26 Daml and Haskell\n\nFor a better learning experience, sign up and enroll in this free course at: https://daml.talentlms.com/plus/catalog/courses/141","channel_name":"Digital Asset Training","published_at":"2025-02-19T00:00:00.000Z","thumbnail_url":"https://i.ytimg.com/vi/3lSUB3wuAyk/hqdefault.jpg","transcript_text":"Daml as a programming language uses a functional programming paradigm. Let's take a look at what that means. We'll first look at what functional programming is and compare it to imperative programming. Then we'll look at how it's used in Daml. After that, we'll discuss how Haskell has been used as the foundational language for Daml. And finally, we'll take a quick look at the standard library. Let's get started. To help understand the functional paradigm, let's compare it with imperative languages like C, Java and Java Script. In imperative programming, we write instructions for the computer to follow. For example, to add two numbers, we first define two variables, assign them values, and then write the command to add the two variables. In functional programming, on the other hand, we declare functions like mathematical expressions. A function takes one or more values and then maps them to some other values. We declare what the function is, not what the function should do. Let's look at another example. Let's say we wanna write a program that increments a number by one. In the imperative style, we create a variable, initialize it with a value, and then write a command to increment its value and assign it to itself. Notice how we're overriding the value of X with its new value. This means that X is mutable. Its value can change. Because of that, the state of the program also changes. Let's contrast this with how it's done in functional programming. We create a function, say increment, and define it as something that takes one variable X and returns a value X plus one. The X on the left of the equal sign is the input, and on the right is the expression that uses that input to evaluate the output. There's no initialization or overriding the variable X. So when we say increment five, the function gets the value five and returns six. X never changes its value because it is immutable. And as the variable doesn't change values once it's assigned, the state of the function also never changes. Or in other words, it is stateless. You can think of functional programming as a mathematical style of writing. Functional programs declare functions which can be invoked when needed. There are several other characteristics unique to functional programming that we'll learn later in this course. So how does that help in the context of Daml? Using a functional language to write these actions gives us several advantages. First functions are composable. Functions are first class citizens in a functional language, which means they can be used and passed along as arguments to other function. This enables functions to create higher order functions. Functional language also makes the transaction atomic. That is they either succeed or fail completely. It's very difficult and error prone to implement atomic execution of a block code using procedural languages. In Daml, simply including a list of actions in a \"do block\", results in mathematically guaranteed atomic execution of those actions. In other words, from a developer's perspective. You get guaranteed atomic execution by simply inserting a single keyword declaration over a block of code. Finally, as we just saw, the functional paradigm offers immutability of variables and stateless functions. While the benefits of these features may not be immediately apparent, you'll begin to see how they make Daml a well-suited language for writing smart contracts. Daml borrows heavily from Haskell, for example. All the functional programming concepts and Daml come from has. Daml builds upon Haskell to introduce smart contract programming where concepts such as parties, ledgers, and contracts are foundational to build a Daml application. If you're familiar with Haskell, you'll notice that not all Haskell programming constructs are implemented in Daml. For example, the \"with\" syntax of a template and \"dot syntax\" to access record elements is not offered in Haskell. Unlike Haskell, which allows lazy comput, daml is fairly strict and doesn't allow specifying lists with no size. Monads in Haskell are called Actions in Daml. If you don't know Haskell, it's okay. Just continue on and we'll show you how to write functional programs in Daml Before we start writing full applications, there's one more detail about Daml we should mention. Daml also has a rich set of standard libraries like Python or Haskell. You can think of Daml as a batteries included. The Daml Standard Library is bundled with the SDK, and if you're familiar with Haskell, one of the standard library modules is Prelude, which gets automatically imported into any Daml file you create. For those unfamiliar with the Prelude module, think of it as the foundational set of definitions in the language. Let's take a look at what we've covered. The functional paradigm uses expressions or functions to write logic, while the Imperative Paradigm uses a sequence of commands or instruc. Functions are composable. They can be passed on as arguments to create higher order functions. This feature of functional languages allows Daml to build composable applications. The actions defined in the due block of a Daml template need to be atomic, and the functional paradigm helps us achieve that. And, although Daml is based on Haskell, there are some key differences which we need to keep in mind. Finally, don't forget the Daml Standard Library. It has many of the functions that you'll need or will find useful.","transcript_synced_at":"2026-10-26T04:03:45.443Z","segments":[{"start_seconds":0,"text":"Daml as a programming language uses a functional programming paradigm. Let's take a look at what that means.","url":"https://www.youtube.com/watch?v=3lSUB3wuAyk&t=0s"},{"start_seconds":7,"text":"We'll first look at what functional programming is and compare it to imperative programming. Then we'll look at how it's used in Daml.","url":"https://www.youtube.com/watch?v=3lSUB3wuAyk&t=7s"},{"start_seconds":14,"text":"After that, we'll discuss how Haskell has been used as the foundational language for Daml. And finally, we'll take a quick look at the standard library. Let's get started.","url":"https://www.youtube.com/watch?v=3lSUB3wuAyk&t=14s"},{"start_seconds":24,"text":"To help understand the functional paradigm, let's compare it with imperative languages like C, Java and Java Script. In imperative programming, we write instructions for the computer to follow.","url":"https://www.youtube.com/watch?v=3lSUB3wuAyk&t=24s"},{"start_seconds":34,"text":"For example, to add two numbers, we first define two variables, assign them values, and then write the command to add the two variables.","url":"https://www.youtube.com/watch?v=3lSUB3wuAyk&t=34s"},{"start_seconds":42,"text":"In functional programming, on the other hand, we declare functions like mathematical expressions. A function takes one or more values and then maps them to some other values.","url":"https://www.youtube.com/watch?v=3lSUB3wuAyk&t=42s"},{"start_seconds":52,"text":"We declare what the function is, not what the function should do. Let's look at another example. Let's say we wanna write a program that increments a number by one.","url":"https://www.youtube.com/watch?v=3lSUB3wuAyk&t=52s"},{"start_seconds":62,"text":"In the imperative style, we create a variable, initialize it with a value, and then write a command to increment its value and assign it to itself.","url":"https://www.youtube.com/watch?v=3lSUB3wuAyk&t=62s"},{"start_seconds":69,"text":"Notice how we're overriding the value of X with its new value. This means that X is mutable. Its value can change.","url":"https://www.youtube.com/watch?v=3lSUB3wuAyk&t=69s"},{"start_seconds":78,"text":"Because of that, the state of the program also changes. Let's contrast this with how it's done in functional programming.","url":"https://www.youtube.com/watch?v=3lSUB3wuAyk&t=78s"},{"start_seconds":84,"text":"We create a function, say increment, and define it as something that takes one variable X and returns a value X plus one.","url":"https://www.youtube.com/watch?v=3lSUB3wuAyk&t=84s"},{"start_seconds":93,"text":"The X on the left of the equal sign is the input, and on the right is the expression that uses that input to evaluate the output.","url":"https://www.youtube.com/watch?v=3lSUB3wuAyk&t=93s"},{"start_seconds":101,"text":"There's no initialization or overriding the variable X.","url":"https://www.youtube.com/watch?v=3lSUB3wuAyk&t=101s"},{"start_seconds":104,"text":"So when we say increment five, the function gets the value five and returns six. X never changes its value because it is immutable.","url":"https://www.youtube.com/watch?v=3lSUB3wuAyk&t=104s"},{"start_seconds":114,"text":"And as the variable doesn't change values once it's assigned, the state of the function also never changes. Or in other words, it is stateless.","url":"https://www.youtube.com/watch?v=3lSUB3wuAyk&t=114s"},{"start_seconds":123,"text":"You can think of functional programming as a mathematical style of writing. Functional programs declare functions which can be invoked when needed.","url":"https://www.youtube.com/watch?v=3lSUB3wuAyk&t=123s"},{"start_seconds":131,"text":"There are several other characteristics unique to functional programming that we'll learn later in this course. So how does that help in the context of Daml?","url":"https://www.youtube.com/watch?v=3lSUB3wuAyk&t=131s"},{"start_seconds":140,"text":"Using a functional language to write these actions gives us several advantages. First functions are composable.","url":"https://www.youtube.com/watch?v=3lSUB3wuAyk&t=140s"},{"start_seconds":148,"text":"Functions are first class citizens in a functional language, which means they can be used and passed along as arguments to other function. This enables functions to create higher order functions.","url":"https://www.youtube.com/watch?v=3lSUB3wuAyk&t=148s"},{"start_seconds":159,"text":"Functional language also makes the transaction atomic. That is they either succeed or fail completely.","url":"https://www.youtube.com/watch?v=3lSUB3wuAyk&t=159s"},{"start_seconds":165,"text":"It's very difficult and error prone to implement atomic execution of a block code using procedural languages.","url":"https://www.youtube.com/watch?v=3lSUB3wuAyk&t=165s"},{"start_seconds":172,"text":"In Daml, simply including a list of actions in a \"do block\", results in mathematically guaranteed atomic execution of those actions.","url":"https://www.youtube.com/watch?v=3lSUB3wuAyk&t=172s"},{"start_seconds":181,"text":"In other words, from a developer's perspective.","url":"https://www.youtube.com/watch?v=3lSUB3wuAyk&t=181s"},{"start_seconds":184,"text":"You get guaranteed atomic execution by simply inserting a single keyword declaration over a block of code.","url":"https://www.youtube.com/watch?v=3lSUB3wuAyk&t=184s"},{"start_seconds":192,"text":"Finally, as we just saw, the functional paradigm offers immutability of variables and stateless functions.","url":"https://www.youtube.com/watch?v=3lSUB3wuAyk&t=192s"},{"start_seconds":197,"text":"While the benefits of these features may not be immediately apparent, you'll begin to see how they make Daml a well-suited language for writing smart contracts.","url":"https://www.youtube.com/watch?v=3lSUB3wuAyk&t=197s"},{"start_seconds":206,"text":"Daml borrows heavily from Haskell, for example. All the functional programming concepts and Daml come from has.","url":"https://www.youtube.com/watch?v=3lSUB3wuAyk&t=206s"},{"start_seconds":213,"text":"Daml builds upon Haskell to introduce smart contract programming where concepts such as parties, ledgers, and contracts are foundational to build a Daml application.","url":"https://www.youtube.com/watch?v=3lSUB3wuAyk&t=213s"},{"start_seconds":223,"text":"If you're familiar with Haskell, you'll notice that not all Haskell programming constructs are implemented in Daml.","url":"https://www.youtube.com/watch?v=3lSUB3wuAyk&t=223s"},{"start_seconds":229,"text":"For example, the \"with\" syntax of a template and \"dot syntax\" to access record elements is not offered in Haskell.","url":"https://www.youtube.com/watch?v=3lSUB3wuAyk&t=229s"},{"start_seconds":236,"text":"Unlike Haskell, which allows lazy comput, daml is fairly strict and doesn't allow specifying lists with no size.","url":"https://www.youtube.com/watch?v=3lSUB3wuAyk&t=236s"},{"start_seconds":244,"text":"Monads in Haskell are called Actions in Daml. If you don't know Haskell, it's okay.","url":"https://www.youtube.com/watch?v=3lSUB3wuAyk&t=244s"},{"start_seconds":249,"text":"Just continue on and we'll show you how to write functional programs in Daml Before we start writing full applications, there's one more detail about Daml we should mention.","url":"https://www.youtube.com/watch?v=3lSUB3wuAyk&t=249s"},{"start_seconds":259,"text":"Daml also has a rich set of standard libraries like Python or Haskell. You can think of Daml as a batteries included.","url":"https://www.youtube.com/watch?v=3lSUB3wuAyk&t=259s"},{"start_seconds":267,"text":"The Daml Standard Library is bundled with the SDK, and if you're familiar with Haskell, one of the standard library modules is Prelude, which gets automatically imported into any Daml file you create.","url":"https://www.youtube.com/watch?v=3lSUB3wuAyk&t=267s"},{"start_seconds":279,"text":"For those unfamiliar with the Prelude module, think of it as the foundational set of definitions in the language. Let's take a look at what we've covered.","url":"https://www.youtube.com/watch?v=3lSUB3wuAyk&t=279s"},{"start_seconds":289,"text":"The functional paradigm uses expressions or functions to write logic, while the Imperative Paradigm uses a sequence of commands or instruc.","url":"https://www.youtube.com/watch?v=3lSUB3wuAyk&t=289s"},{"start_seconds":297,"text":"Functions are composable. They can be passed on as arguments to create higher order functions.","url":"https://www.youtube.com/watch?v=3lSUB3wuAyk&t=297s"},{"start_seconds":303,"text":"This feature of functional languages allows Daml to build composable applications.","url":"https://www.youtube.com/watch?v=3lSUB3wuAyk&t=303s"},{"start_seconds":308,"text":"The actions defined in the due block of a Daml template need to be atomic, and the functional paradigm helps us achieve that.","url":"https://www.youtube.com/watch?v=3lSUB3wuAyk&t=308s"},{"start_seconds":315,"text":"And, although Daml is based on Haskell, there are some key differences which we need to keep in mind. Finally, don't forget the Daml Standard Library.","url":"https://www.youtube.com/watch?v=3lSUB3wuAyk&t=315s"},{"start_seconds":323,"text":"It has many of the functions that you'll need or will find useful.","url":"https://www.youtube.com/watch?v=3lSUB3wuAyk&t=323s"}],"youtube_url":"https://youtube.com/watch?v=3lSUB3wuAyk","url":"https://ccpedia.xyz/videos/3lSUB3wuAyk"}