pure function

Scala: What do “effect” and “effectful” mean in functional programming?

When you get started with functional programming (FP) a common question you’ll have is, “What is an effect in functional programming?” You’ll hear advanced FPers use the words effects and effectful, but rarely do you get a definition of what they mean.

Effects are related to monads

The first step in the process of understanding effects is to say that they’re related to monads, so you have to know a little bit about monads to understand effects.

Scala: “IO monad doesn’t make a function pure; it just makes it obvious it’s impure” alvin July 21, 2018 - 11:15am

I always find it confusing when people claim that the IO monad somehow makes an impure function pure. Frankly, I think that argument does a confusing disservice to people who are trying to learn functional programming (FP).

Looking at some differences between Scalaz Task and Scala Future alvin October 29, 2017 - 6:04pm
Table of Contents1 - The Scala Future example2 - The Scalaz Task example3 - What happens when you call the Future twice?4 - What happens when you call the Task twice?5 - Is one approach correct?6 - Source code

Some time ago I was searching for something and came across this Reddit thread about this tweet from Timothy Perrett, who leads Scala teams at Verizon:

“The fact that #scala Future is not lazy just blows my mind. After years of using Scalaz Task, Future is now totally unusable.”

The last part of that tweet is a bit of hyperbole to me, as I’ve been using the Scala Future for a long time myself, and I’ve had no problems using it. That being said, the examples at the top of the Reddit page were interesting, so I decided to try to understand the differences.

Functional Programming is Like Algebra alvin May 28, 2017 - 6:30pm

Some advanced Lispers will cringe when someone says that a function “returns a value.” This is because Lisp derives from something called lambda calculus, which is a fundamental programming-like algebra developed by Alonzo Church.

This is a page from my book, Functional Programming, Simplified

Pure Function Signatures Tell All

“In Haskell, a function’s type declaration tells you a whole lot about the function, due to the very strong type system.”

Learn You a Haskell for Great Good!

One thing you’ll find in FP is that the signatures of pure functions tell you a lot about what those functions do. In fact, it turns out that the signatures of functions in FP applications are much more important than they are in OOP applications. As you’ll see in this lesson:

This is a page from my book, Functional Programming, Simplified

The “Great FP Terminology Barrier”

“They say no ship can survive this.”

Hikaru Sulu, talking about “The Great Barrier”
(Star Trek V: The Final Frontier)

A short excursion to ... The Twilight Zone

Hello, Rod Serling of The Twilight Zone here. Al will be back shortly, but for now, let me take you to another place and time ... an alternate universe ...

This is a page from my book, Functional Programming, Simplified

Rules for Programming in This Book

“Learn the rules like a pro, so you can
break them like an artist.”

Pablo Picasso

“Learn the rules, and then forget them.”
Haiku Master Matsuo Basho

Alright, that’s enough of the “preface” material, let’s get on with the book!

As I wrote earlier, I want to spare you the route I took of, “You Have to Learn Haskell to Learn Scala/FP,” but, I need to say that I did learn a valuable lesson by taking that route:

Question Everything alvin May 28, 2017 - 5:26pm

“I have no special talent. I am only passionately curious.”

Albert Einstein

A Golden Rule of this book is to always ask, “Why?” By this I mean that you should question everything I present. Ask yourself, “Why is this FP approach better than what I do in my OOP code?” To help develop this spirit, let’s take a little look at what FP is, and then see what questions we might have about it.