Is This a Monad?

References Monad English Wiki: https://en.wikipedia.org/wiki/Monad_(functional_programming) Function English Wiki: https://en.wikipedia.org/wiki/Function_(mathematics) Function Korean Wiki: https://ko.wikipedia.org/wiki/함수 Introduction This time, I want to take a different approach. Instead of explaining what a monad is right away, let’s consider the problems encountered when composing functions, and then present solutions to understand what can be called a monad. So, let’s first revisit what a function is, to improve understanding, and then explain the problematic example. Please note that this post contains personal opinions. As the title suggests, I can’t confidently say “this is a monad!” ...

June 25, 2023

Lambda Expression and Method Reference Differences

Users Sort by last name If the last names are the same, sort by first name Then return as a List. I created an example for cases where there are two sorting criteria. And I tried to solve the problem using method reference and lambda expression… but what happened… The example written with a lambda expression results in a compile error. Huh! Is it not able to infer the type well…? They look exactly the same, though. ...

October 13, 2022

Stream API Practice

Recently, I read the book Modern Java In Action. I was very impressed. I realized that when studying functional programming and the Java API, I should read books. Compared to Googling, books are much richer in content and much more reliable. After all, it was written by a Java Champion, two professors, and one engineer! Anyway, I will leave some code I wrote while studying the stream API. And I will gradually share the ideas behind why I wrote the code this way. ...

October 13, 2022

Closure

Introduction Let’s look up the word ‘closure’ in English. Dictionary: an act or process of closing something, especially an institution, thoroughfare, or frontier, or of being closed. It means ’to close’. So, when I first studied closures, it didn’t make sense to me. What is being closed? Today, let’s lift the veil! The Concept of Closure Lambda calculus is a concept from the 1930s, and closure is from the 1960s. ...

August 8, 2021

Lazy Evaluation

Introduction The concept of lazy evaluation is not difficult. So, this time, I will focus on its usefulness. Background Knowledge If you are confused between expression and evaluation, please refer to the following article: https://jurogrammer.tistory.com/129 Definition Lazy evaluation is a strategy where the evaluation of an expression is delayed until its value is needed. It is usually used to improve performance. Let’s see how delaying evaluation can improve performance. Example of Performance Improvement Here is an example where a value is only used if a certain condition is met. ...

August 8, 2021

Functional Implementation of the Decorator Pattern

Motivation This time, the introduction is a bit long… Feel free to skip it. It all started with trying to understand the concept of flux. So, I was implementing a brick breaker game using redux + canvas. (Somehow, after some trial and error, I found that I could use redux without react.) Problem - I want to notify only the relevant renderer when the state changes. In redux, when the state changes, the rendering logic subscribed to a specific state change is executed. ...

June 19, 2021

Lambda Calculus - Boolean Operation

Source https://www.youtube.com/watch?v=3VQ382QG-y4 Lambda Calculus, Expressed as Boolean! In this post, let’s see how lambda calculus can be converted into boolean operations. The explanation is based on the referenced video, as the content on Wikipedia alone was not sufficient for understanding. Structure of the Post This post is written in two parts. In the first part, I will introduce functions by replacing the terms used in lambda calculus with bird names. This helps reduce preconceptions and confusion. ...

March 21, 2021

Lambda Calculus - Formal Summary (Reduction)

Source https://en.wikipedia.org/wiki/Lambda_calculus Reduction The dictionary definition of reduction is as follows: the action or fact of making a specified thing smaller or less in amount, degree, or size. In other words, it is the act or fact of reducing the amount, dimension, or size of something. Meaning Wikipedia introduces reduction as follows: The meaning of lambda expression is defined by how expressions can be reduced So, the meaning of lambda calculus depends on how expressions are reduced. The referenced title is: ...

February 7, 2021

Lambda Calculus - Formal Summary

Reference https://en.wikipedia.org/wiki/Lambda_calculus#:~:text=Lambda%20calculus%20(also%20written%20as,to%20simulate%20any%20Turing%20machine Overview In the previous post, I explained lambda calculus informally. This time, let’s take a look at a more mathematical (formal) definition. If you want to deeply understand lambda calculus, you need to get used to the formal definition. Most resources are written formally… Formal definition Components of a lambda expression variables v1, v2… the abstraction symbols λ (lambda) and . (dot) parentheses () The set of lambda expressions (Λ) is defined inductively: If x is a variable, then x ∈ Λ. If x is a variable and M ∈ Λ, then (λx.M) ∈ Λ. If M, N ∈ Λ, then (M N) ∈ Λ. In summary: “If you apply lambda operations to lambda components, the result is still a lambda expression!” ...

January 24, 2021

Lambda Calculus - Informal Summary

Source https://en.wikipedia.org/wiki/Lambda_calculus Prerequisite Materials https://jurogrammer.tistory.com/131 Lambda Calculus Intro https://jurogrammer.tistory.com/132 Formal System Overview In this post, I will explain lambda calculus informally. Right, if you start with a formal explanation, it’s hard to understand and hard to grasp the context. So, we’ll look at formal definitions, arithmetic, booleans, and simulation next time. To explain lambda calculus again: It’s a formal system, a mathematical logic for expressing computation. What kind of computation? ...

January 10, 2021