Skip to content

New BlogPost: Recursion, Thunks and Trampolines with Java and Scala #310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions _posts/2025-01-20-algebraic-data-types-with-java.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ This is the first post in a series exploring types and type systems. Other pos

- [Higher-Kinded Types with Java and Scala]({{site.baseurl}}/2025/04/11/higher-kinded-types-with-java-and-scala.html)

- [Recursion, Thunks and Trampolines with Java and Scala]({{site.baseurl}}/2025/05/02/recursion-thunks-trampolines-with-java-and-scala.html)

When we develop an application, we frequently need to model some aspect of business to describe and solve a business problem. We do this by creating a conceptual representation of the real-world problem that we are trying to solve. This allows us to understand the "domain" where our software operates.

## Domain Modelling
Expand Down
2 changes: 2 additions & 0 deletions _posts/2025-02-17-variance-in-java-and-scala.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ This is the second post in a series exploring types and type systems. Other po

- [Higher-Kinded Types with Java and Scala]({{site.baseurl}}/2025/04/11/higher-kinded-types-with-java-and-scala.html)

- [Recursion, Thunks and Trampolines with Java and Scala]({{site.baseurl}}/2025/04/11/recursion-thunks-trampolines-with-java-and-scala.html)

## Variance in Generics

Generics are a fundamental pillar of modern type-safe programming languages. They allow us to write reusable code that can work with different types without sacrificing type safety. But when you dive deeper into the world of generics, you encounter the intriguing concepts of *covariance* and *contravariance*. These concepts, often perceived as complex, are crucial for understanding how type hierarchies and subtyping interact with generic types.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ This is the third post in a series exploring types and type systems. Other pos

- [Higher-Kinded Types with Java and Scala]({{site.baseurl}}/2025/04/11/higher-kinded-types-with-java-and-scala.html)

- [Recursion, Thunks and Trampolines with Java and Scala]({{site.baseurl}}/2025/05/02/recursion-thunks-trampolines-with-java-and-scala.html)

## Intersection and Union Types with Java and Scala

One of the difficult things for modern programming languages to get right is around providing flexibility when it comes to expressing complex relationships. As languages evolve, they need to give us tools to model the nuances of real world problems more accurately in our code.
Expand Down
7 changes: 7 additions & 0 deletions _posts/2025-03-31-functors-monads-with-java-and-scala.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ This is the fourth post in a series exploring types and type systems. Other pos

- [Higher-Kinded Types with Java and Scala]({{site.baseurl}}/2025/04/11/higher-kinded-types-with-java-and-scala.html)

- [Recursion, Thunks and Trampolines with Java and Scala]({{site.baseurl}}/2025/05/02/recursion-thunks-trampolines-with-java-and-scala.html)


In this post we will combine some ideas from functional programming with strong typing to produce robust expressive code that is more reusable.

Expand Down Expand Up @@ -539,3 +541,8 @@ Scala's for comprehensions and typeclasses (like those in Cats) make working wit
### Next time

Next time we build on the concepts of __Functor__ and __Monads__ taking the abstraction to the next level with [Higher-Kinded Types]({{site.baseurl}}/2025/04/11/higher-kinded-types-with-java-and-scala.html) to write more reusable code and reducing code duplication.

further reading:

- Presentation: [Cleaner, More Expressive Java
using Functors and Monads](https://magnussmith.github.io/functor-monad-presentation/)
3 changes: 2 additions & 1 deletion _posts/2025-04-11-higher-kinded-types-with-java-and-scala.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ This is the fifth post in a series exploring types and type systems. Other post

- [Functors and Monads with Java and Scala]({{site.baseurl}}/2025/03/31/functors-monads-with-java-and-scala.html)

- [Recursion, Thunks and Trampolines with Java and Scala]({{site.baseurl}}/2025/05/02/recursion-thunks-trampolines-with-java-and-scala.html)

In this post we will build upon our knowledge of `Functors` and `Monads` from the previous post to open up the next level of abstraction.

Expand Down Expand Up @@ -540,4 +541,4 @@ This native approach makes functional patterns based on HKTs feel like a natural

## Next time

Next time we conclude this series on type systems by looking at __Thunks__ and __Trampolines__ and how they can help solve problems when working with recursion where it can pay to be lazy.
Next time we conclude this series on type systems by looking at [__Thunks__ and __Trampolines__]({{site.baseurl}}/2025/05/02/recursion-thunks-trampolines-with-java-and-scala.html) and how they can help solve problems when working with recursion where it can pay to be lazy.
415 changes: 415 additions & 0 deletions _posts/2025-05-02-recursion-thunks-trampolines-with-java-and-scala.md

Large diffs are not rendered by default.

Binary file added magnussmith/assets/functional_xkcd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added magnussmith/assets/recursion.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file added magnussmith/assets/trampoline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.