Functional Programming on Kevin Sookocheff
https://sookocheff.com/tags/functional-programming/
Recent content in Functional Programming on Kevin SookocheffHugo -- gohugo.ioen-uskevin@sookocheff.com (Kevin Sookocheff)kevin@sookocheff.com (Kevin Sookocheff)Thu, 18 Oct 2018 09:16:45 -0600Alpha Conversion
https://sookocheff.com/post/fp/alpha-conversion/
Thu, 18 Oct 2018 09:16:45 -0600kevin@sookocheff.com (Kevin Sookocheff)https://sookocheff.com/post/fp/alpha-conversion/Alpha conversion (also written \(\alpha\)-conversion) is a way of removing name clashes in expressions.
A name clash arises when a \(\beta\)-reduction places an expression with a free variable in the scope of a bound variable with the same name as the free variable.
— Greg Michaelson, An Introduction to Functional Programming Through Lambda Calculus
When we are performing a \(beta\)-reduction it is possible that the variable name in an inner expression is the same as a variable name in an outer expression.Beta Reduction
https://sookocheff.com/post/fp/beta-reduction/
Thu, 04 Oct 2018 09:16:45 -0600kevin@sookocheff.com (Kevin Sookocheff)https://sookocheff.com/post/fp/beta-reduction/Formally, beta reduction (also written \(\beta\)-reduction) is the replacement of a bound variable in a function body with a function argument. The purpose of \(\beta\)-reduction is to compute the result of a function by function application using specific rules.
More formally, the beta reduction rule states that a function application of the form \((\lambda x.t)s\) reduces to the term \(t[x := s]\). The term \(t[x := s]\) means that all instances of \(x\) in \(t\) are replaced with \(s\).Eta Reduction
https://sookocheff.com/post/fp/eta-conversion/
Thu, 27 Sep 2018 10:16:45 -0600kevin@sookocheff.com (Kevin Sookocheff)https://sookocheff.com/post/fp/eta-conversion/The purpose of eta reduction (also written \(\eta\)-reduction) is to drop an abstraction over a function to simplify it. This is possible when there is nothing more that a function can do to its argument. For example, imagine that we have a simple function \( f\ x = g\ x \). Both \(g\) and \(f\) take the same argument, \(x\), and the function application function results in the same value (specified by the equality symbol).Normal, Applicative and Lazy Evaluation
https://sookocheff.com/post/fp/evaluating-lambda-expressions/
Tue, 18 Sep 2018 10:26:45 -0600kevin@sookocheff.com (Kevin Sookocheff)https://sookocheff.com/post/fp/evaluating-lambda-expressions/A lambda expression is said to be in normal form if it cannot be reduced any further, meaning that the expression no longer contains any function applications. More formally, a reducible expression is called a redex, and a lambda expression is in normal form when it contains no more redexes.
Redex A reducible function expression. Normal Form A lambda expression that contains no redexes. Given a lambda expression, there are two primary strategies for reducing it to normal form: normal-order evaluation, or applicative-order evaluation.Representing Pairs and Lists in Lambda Calculus
https://sookocheff.com/post/fp/representing-pairs-and-lists-in-lambda-calculus/
Fri, 07 Sep 2018 09:20:45 -0600kevin@sookocheff.com (Kevin Sookocheff)https://sookocheff.com/post/fp/representing-pairs-and-lists-in-lambda-calculus/Having covered types, let’s now turn our attention to lists. Lists are general purpose data structures for storing sequences of items. In lambda calculus, lists are represented using pairs, with the first item of the pair representing the head of the list, and the second item representing the rest of the list. A special value, nil, at as the second item of the pair terminates the list.
Pairs Let’s start by focusing on pairs (or tuples).Typed Lambda Calculus
https://sookocheff.com/post/fp/typed-lambda-calculus/
Tue, 21 Aug 2018 09:26:45 -0600kevin@sookocheff.com (Kevin Sookocheff)https://sookocheff.com/post/fp/typed-lambda-calculus/Lambda calculus is a very simple language. If you take away any syntactic sugar, all you are left with is functions that take arguments and return results. You can use these simple building blocks to construct functions that represent numbers and arithmetic, but there is no way to restrict, for example, arithmetic functions to require numeric operands. This is where types come in. Generally speaking, types allow you to control the use of functions so that only meaningful combinations of inputs and outputs are used.Recursive Lambda Functions the Y-Combinator
https://sookocheff.com/post/fp/recursive-lambda-functions/
Mon, 11 Jun 2018 11:38:45 -0600kevin@sookocheff.com (Kevin Sookocheff)https://sookocheff.com/post/fp/recursive-lambda-functions/In a purely functional language — like lambda calculus — programs are expressed as nested function calls. Repetition in such an environment requires that nesting of function calls continues until some condition is met. During the repetition, each function passes its result to the next function in the nested chain and this repetition is completed when a test for some condition passes. The repetitive behaviour I’ve just described is recursion:Simplifying Lambda Syntax
https://sookocheff.com/post/fp/simplifying-lambda-syntax/
Fri, 25 May 2018 09:26:45 -0600kevin@sookocheff.com (Kevin Sookocheff)https://sookocheff.com/post/fp/simplifying-lambda-syntax/Evaluating lambda functions requires using lots of brackets, which can be tedious and are a major source of error for evaluating expressions by hand. To simplify expressions, you can omit brackets when it is clear what the intention of the function is. Particularly, a function application can omit the brackets surrounding each individual parameter and assume the function is applied to the nearest argument. So, instead of expressing a function of three arguments asIntroducing Lambda Calculus
https://sookocheff.com/post/fp/introducing-lambda-calculus/
Fri, 27 Apr 2018 09:26:45 -0600kevin@sookocheff.com (Kevin Sookocheff)https://sookocheff.com/post/fp/introducing-lambda-calculus/Lambda calculus provides some of the foundational structures that functional programming is built from. It therefore seems fitting to start my journey through functional programming with a thorough examination of lambda calculus. This first post will introduce Lambda calculus with references to the book An Introduction to Functional Programming Through Lambda Calculus.
Syntax The complete syntax for Lambda calculus is surprisingly small and comprehensible. This section lists the syntax in its entirety, while following sections break the syntax down to explain each part.Range, Domain, and Codomain
https://sookocheff.com/post/fp/domain-range-codomain/
Fri, 09 Mar 2018 10:26:45 -0600kevin@sookocheff.com (Kevin Sookocheff)https://sookocheff.com/post/fp/domain-range-codomain/Three common terms come up whenever we talk about functions: domain, range, and codomain. This post clarifies what each of those terms mean.
Before we start talking about domain and range, lets quickly recap what a function is:
A function relates each element of a set with exactly one element of another set (possibly the same set).
Math is Fun That is, a function relates an input to an output.A Functional Programming Learning Plan
https://sookocheff.com/post/fp/a-functional-learning-plan/
Fri, 09 Feb 2018 10:26:45 -0600kevin@sookocheff.com (Kevin Sookocheff)https://sookocheff.com/post/fp/a-functional-learning-plan/I’m documenting my journey from functional neophyte to (hopefully) functional programmer by writing a series of blog posts on the topic. So far I’ve covered what functional programming is and why you would want to learn about it. In this post, I’m going to describe the resources I will be using to become functionally fluent.
Although I have previously said I’m learning about functional programming, I should be more specific.Practical Differences Between Functional and Imperative Programming
https://sookocheff.com/post/fp/differences-between-imperative-and-functional/
Fri, 02 Feb 2018 10:26:45 -0600kevin@sookocheff.com (Kevin Sookocheff)https://sookocheff.com/post/fp/differences-between-imperative-and-functional/I previously talked about what functional programming is by comparing it to other programming paradigms. This post expands on that post to talk specifically about practical differences between functional programming and the paradigm most of us are intimately familiar with — imperative. This post is punctuated with some quotes from the book An Introduction to Functional Programming Through Lambda Calculus.
It’s worth noting that each of these practical differences are enabled because of the power of referential transparency.Why Functional Programming? The Benefits of Referential Transparency
https://sookocheff.com/post/fp/why-functional-programming/
Fri, 02 Feb 2018 10:26:45 -0600kevin@sookocheff.com (Kevin Sookocheff)https://sookocheff.com/post/fp/why-functional-programming/Having covered what functional programming is, I wanted to spend a minute or two discussing why I want to learn functional programming in the first place. I’m sure we have all heard vague things about “side-effects”, “immutability”, and “composition”, but I wanted to dive a bit deeper on the topic to describe what — to me — is important about functional programming.
Referential Transparency The key differentiating feature of (pure) functional programs is that they provide referential transparency.What is Functional Programming?
https://sookocheff.com/post/fp/what-is-functional-programming/
Tue, 23 Jan 2018 10:26:45 -0600kevin@sookocheff.com (Kevin Sookocheff)https://sookocheff.com/post/fp/what-is-functional-programming/I’m documenting my journey from functional neophyte to (hopefully) functional programmer by writing a series of blog posts on the topic. This is the first post describing what, exactly, the word functional programming means.
Functional programming is a programming paradigm that lives alongside other programming paradigms. None of these paradigms have a precise, unanimous definition or standard, and there is not real agreement on which paradigm is better or worse for building particular types of software.