💡Block
Ken Okabe
Posted on January 17, 2024
Unknown Unknowns "the ones you don’t know you don’t know"
Functor and Monad at a Glance
💡Block
Introduction to outline of functional programming
Functional code is assembled like LEGO blocks
The basic principle of LEGO blocks is to "connect two blocks together to create a new block"
- The blocks of functional code are actually expressions (mathematical expressions)
- The way LEGO blocks are connected is "fitting the bumps and holes", which is the only way, but the way blocks of expressions are connected is infinite
- When LEGO blocks are connected by "fitting the bumps and holes", of course the "shape and size of the bumps and holes" must match, and such rules are called standards in the industrial world, and the USB standard is well known
- When two expressions (blocks) are connected by an operator, the operator and the expressions must match the standard, which is called standard in the industrial world, but in the world of programming, it corresponds to something called Type
The similarity between the "standard" of the industrial world and the "type" of the programming world
What is the "type" of the programming world, or more precisely, the "type" as a mathematical entity? We will dig deeper into this later, but as a rough image for the first entrance, you can understand it as something like the "standard" of the industrial world
- Since there are infinite ways to connect blocks of expressions, there are also infinite types
- Among the infinite ways of connecting blocks of expressions, the four methods of addition, subtraction, multiplication, and division are taught in elementary school arithmetic and are called arithmetic operations
- This way of connecting two expressions (blocks) is called binary operation, and arithmetic operations are members of binary operations
- The (binary) operators that connect two expressions (blocks) are
- The type that matches the expressions (blocks) to be connected is a number
- A binary operation that connects two expressions (blocks) and with the operator
- A binary operation that connects two expressions (blocks) and with the operator
- is a new expression (block) that is assembled by connecting two expressions (blocks)
- Therefore, as long as you can connect two expressions (blocks), it is just a repetition of the same thing, and you can freely connect three or more expressions (blocks) by combining the same connection or different connections , etc.
- Functional programming is a method of doing everything only by connecting and assembling blocks like this
- So in the end? Functional programming is just building mathematical expressions like , so it can be said to be mathematics itself
- Since we have already done this kind of operation in arithmetic and mathematics classes, we have already mastered the basics of functional programming! 🥳🎉
Programming languages where code is composed of expressions
Relatively new programming languages such as Rust and Verse have a strong functional character, and in principle, code is composed of expressions
Statements and expressions
Rust is primarily an expression language. This means that most forms of evaluation produce or cause a value, and evaluation is guided by a unified syntax category called expressions. Each kind of expression can usually be nested within other kinds of expressions, and the rules for evaluating an expression specify both the value it produces and the order in which its subexpressions are themselves evaluated.
In contrast, statements are primarily used to contain expressions and sequence their evaluation.
As explained in the references of Rust and Verse, which emphasize that code can be written in expressions at the beginning, the content is exactly the same as what was introduced in this chapter, and it is the most basic and fundamental nature of functional code
Posted on January 17, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.