Skip to main content

· 5 min read

Why ADT?

(If you want to get straight to the solution, just click this.)
If you do Functional Programming in Scala, you probably write lots of Algebraic Data Types (ADT). If you're not sure what it is or why we use or what benefits it offers, here is a good blog post written by Charles O'farrell about The Expression Tradeoff which can give you a good idea of why we use ADT. I strongly recommend reading it.

· 4 min read

I was testing a typeclass instance of BigDecimal in my personal FP library using Hedgehog and found some issue in BigDecimal in Scala 2.13.

[info] - just.fp.MonoidSpec.testBigDecimalMonoidLaw: Falsified after 3 passed tests
[info] > a1: A: 1.0000000000000002E+36
[info] > a2: A: -9223372036854775808
[info] > a3: A: -9223372036835934692
[info] > monoidLaw.associativity

It says the test in associativity law failed which means
((a1 |+| a2) |+| a3) is not equal to (a1 |+| (a2 |+| a3)).

That was a Monoid typeclass instance for BigDecimal but it also means the following code returns false.

· 4 min read

There was Scala 2.13.1 release recently and sbt 1.3.0 was release in early September. sbt 1.3.1 was also released just about two weeks after sbt 1.3.0 release.

I'd like to talk about some improvement in Scala 2.13 (not just 2.13.1). Yet, before doing that, I'd like to quickly mention one thing that sbt 1.3.x has much better than the previous versions.

· 4 min read

I used to use Ubuntu Linux most of the time, yet I'm using Mac OS X more these days. I'm quite satisfied with it, but there's one thing inconvenient. That's installing JDK. On Ubuntu, installing Java 8 (technically what I want to install is JDK 8 but since Java has really terrible versioning history, I'll just call it Java 8) is not supported by Canonical, but it can be done easily by the PPA provided by Web Upd8 (Thanks Web Upd8).

On OS X, as we all know, PPA-like solution is Homebrew (hereinafter referred to as 'brew'). I use brew to install Scala and SBT but there's no brew formula for Java. So I need to download the JDK from Oracle's Java website and install it manually or there is a brew-friendly alternative that is 'Homebrew Cask'.

So I can simply do

· 6 min read
  • Last Updated: 2013-08-26 * Fixed: Bug in the gitpullall() script. - 2013-07-23
  • Refactored: gitpullall() - 2013-08-26
  • Updated: gitpullall() - 2015-03-07: Now it can handle branches. So pulling on branch works. The old version always pulled from master. This version uses the name of current branch then get the same one from the remote. (e.g. remote: github, local branch: some-fix <=pull= github/some-fix)
  • Added: gitpullall() for Z shell (zsh) - 2015-03-07

Both Github and Bitbucket are good SCM hosting services. For some reason, you probably want to migrate your project from Github to Bitbucket or vice versa. It's easy because you just need to change the remote repository info. Sometimes, you want to keep your code in both places which means you want to push it to both Github and Bitbucket.

Pushing to both Github and Bitbucket is easy.

· 28 min read

It is surprising to see that there are still many people who do not use generics even when they are using JDK 5 or higher. I can often see it especially when I teach some Java programming subjects at uni. Generics can be very useful and I use it a lot in my libraries and projects. So I'd like to talk about generics but not a basic knowledge of it. I will talk about Java generics in real life programming and how it can be useful as well as some unusual cases may occur and annoy you. I am also going to explain some common cases of generics usage in my next post that I have plan to write soon (hopefully). Then I'm going to write about more complex cases in the sense that it's complex when it's designed but rather simple when it's used, and it's also more practical. It means I'll probably write two more posts about generics so stay tuned if you're interested.