DISCOVERY

October 20th, 2018

Functional Programming

Higher Order Functions

A common higher-order function in functional programming is a fold (also referred to as reduce or inject depending on the language). The goal of a fold is to take a list and reduce it into a single value. Haskell implements multiple fold functions, each of which has a different implementation. This article clears up the differences between each fold function and introduces some simple use cases.

##### foldl and foldr

DISCOVERY

November 17th, 2018

Haskell provides multiple ways to declare types. Some types are simply aliases for existing types, while some are completely new. This post explains the differences between the three mechanisms for creating types in Haskell.

The first keyword for declaring types in Haskell is type. type creates an alias for an existing type (also commonly called a type synonym)1. For example, the following code creates a type Song which is an alias for a tuple containing a string and a list of strings.

DISCOVERY

January 1st, 2019

Functional Programming

Object Oriented Programming

In this article, I'm exploring classes in Haskell. Coming from object oriented languages, the concept of Haskell classes was a bit confusing for me. Haskell is a functional programming language, so its class functionality doesn't match classes in object oriented languages such as Java or Python. The closest comparison for Haskell classes in the object oriented world is Java interfaces with default methods1. This article clears the confusion of Haskell classes.

##### Type Classes

DISCOVERY

August 3rd, 2019

Functional Programming

In my last Haskell Article I discussed functors, which provide a generic way to map functions over values. In this article I'm exploring applicatives, which build on top of functors. After discussing applicatives in Haskell, I'll try implementing them in Java.

##### Applicative Basics

DISCOVERY

May 28th, 2019

Java

Functional Programming

Right now I'm learning Haskell, a functional programming language. In my last few Haskell articles I've discussed basic aspects of the language. Now I've begun digging into advanced functional programming concepts. This article discusses functors, a generic way to map functions over objects.

##### Functor Basics

A common pattern in programming is looping through a collection of values and applying a transformation to each. For example, a programmer might loop through a list of integers and increment each value. The imperative approach to this transformation sets up a for loop and iterates over each list index. The functional approach uses the map higher-order function. map accepts two arguments - a collection to iterate over and a function. The function is applied to each item in the collection.

DISCOVERY

November 6th, 2018

Functional Programming

+4 More

I often use function compositions which pass the result of one function to the argument of another function. In many modern languages function compositions appear as method chains. In Haskell, function compositions are given their own language operator! The composition of two functions f(x) and g(x) is easily defined using mathematical notation:

$(f \circ g)(x)$

DISCOVERY

October 6th, 2018

Functional Programming in Haskell: Part I

Functional Programming

Lambda Functions

In my recent programming adventures, I’ve run into a lot of code that follows a functional style. Many object-oriented and imperative programming languages added basic functional programming features to their specs, including Java 8 in 2014. I’ve spent time looking at functional programming features in these languages, such as currying and lambda functions. Learning the functional programming style through a traditional object-oriented language is fine, but I really wanted to apply functional concepts in a language built upon the functional programming paradigm. Over the past few weeks, I’ve spent some of my free time reading about Haskell, a functional programming language. This post covers some of the functional concepts I explored in my first 200 lines of Haskell code.

##### Guarded Equations

DISCOVERY

August 27th, 2018

Currying Groovy Closures

Groovy

+3 More

Something I'm really interested in is incorporating functional programming practices into my code. Despite not working in any purely functional languages (although I am starting to look at Haskell), most imperative and object oriented languages support certain functional operations. In my recent exploration of Groovy, I noticed that closures support the currying technique. Currying in Groovy takes an existing function and creates a new specialized variant. This post explains how to use currying to enhance Groovy closures.

My exploration of Groovy wasn't the first time I crossed paths with currying. Currying was mentioned in my readings on Java 8 along with my brief research so far of Haskell (a functional programming language). Currying is named after Haskell Curry, an American mathematician (the Haskell language is also named after Curry)1,2. The goal of currying in Groovy is to make specialized versions of a function. To accomplish this, pieces of a function are put into a fixed state prior to invocation.

DISCOVERY

August 18th, 2019

Revisiting Type Equality

Java

JavaScript

+15 More

In this article I'm revisiting the concept of type equality. Type equality is a topic that software engineers learn early on in their careers. Similar to any other profession, it's beneficial to go back to the basics for practice. Professional basketball players practice layups before each game. Professional programmers should work at the basics as well. I spent this past week re-learning type equality in 13 different languages. In the process I've reaffirmed my knowledge and gained new insights. The rest of this article discusses my findings.