Introduction to Functional Programming Part 4: Typed Lambda Calculus | 株式会社taiziii(タイジー)
CONTACT
システム開発・AI導入なら株式会社taiziii コラム Introduction to Functional Programming Part 4: Typed Lambda Calculus
Introduction to Functional Programming Part 4: Typed Lambda Calculus
投稿日:

Introduction to Functional Programming Part 4: Typed Lambda Calculus

This time, it’s about functional programming!

Continuing from last time, let’s explore the theoretical background of functional programming together!

What You Will Learn in This Article

– Typed lambda calculus

Introduction

Having completed learning about lambda calculus in *Introduction to Functional Programming 3*, you’re now ready to study typed lambda calculus. Let’s dive into an explanation of typed lambda calculus.

 

(For information on lambda calculus, check here↓)

Introduction to Functional Programming 3 (Lambda Calculus)

Typed Lambda Calculus

Typed lambda calculus involves assigning types to lambda terms for computation. Types can be either basic types or function types in the form \( A \to B \), using types \( A \) and \( B \). Basic types include examples like the integer type \( i \) or the boolean type \( o \). Each variable is associated with a specific type. For instance, variable \( z \) could have type \( o \), and \( f \) could have type \( i \to i \). If \( f \) has type \( i \to i \) and \( a \) has type \( i \), the type of \( fa \) would be \( i \).

Recall that lambda terms are constructed from variables using abstraction and application. By defining rules for types in abstraction and application, types can be assigned to lambda terms. For abstraction \( \lambda a.M \), if \( a \) has type \( A \) and \( M \) has type \( B \), the type of \( \lambda a.M \) is \( A \to B \). For application \( MN \), if \( M \) has type \( A \to B \) and \( N \) has type \( A \), the resulting type is \( B \). If \( M \) does not have type \( A \to B \) or \( N \) does not have type \( A \), the application \( MN \) is invalid and does not have a type.

Types and Reduction

In the lambda calculus section, we studied \( \beta \)-reduction. A key question is whether \( \beta \)-reduction preserves types. For example, consider the lambda term \( (\lambda x.\lambda y.x)w \) where \( x \), \( y \), and \( w \) all have type \( i \). The type of \( \lambda x.\lambda y.x \) is \( i \to i \to i \), and since \( w \) has type \( i \), the application \( (\lambda x.\lambda y.x)w \) has type \( i \to i \). After \( \beta \)-reduction, \( (\lambda x.\lambda y.x)w \) reduces to \( \lambda y.w \), which also has type \( i \to i \). Thus, the type remains the same before and after \( \beta \)-reduction.

This type preservation during \( \beta \)-reduction is due to the well-defined rules for abstraction and application. Incidentally, the normalization theorem proves the termination of \( \beta \)-reduction, meaning it always halts after a finite number of steps.

Conclusion

In this article, we explained typed lambda calculus. We hope this content helps you write better functional programs. Typed lambda calculus also includes the Curry-Howard correspondence, a fascinating concept that connects proofs with programs and contributes to improving program quality. This is a hot topic and will be introduced in the future. Until next time!
2 indicates independent content and should remain unchanged.[/efn_note]

  1. Text enclosed in 1

この記事の執筆者

加藤晃寿郎

株式会社taiziii 代表取締役 慶應義塾大学で経済学を専攻しながら、エンジニアとして在学中にコスメ系アプリ事業で起業。 上記起業を経て、再度在学中にシステム開発会社を創業。Webのフロント開発からバックエンド開発まで、あらゆるWeb開発、幅広く対応可能なオールラウンダーとして活躍。 大規模開発のためのエンジニアチームを持っているという特性も活かしながら、外部CTOとしても多くの企業の開発課題を解決してきている。 StockSunを含め複数社の事業新規立ち上げ、開発支援を行っており、ビジネス設計を含めた設計及び開発までワンストップで対応している。

SNSでシェアする

各種お問い合わせ