Firstly, I agree with the tom comment that there is nothing wrong with your four-line version. It is beautifully readable. However, it is a fun exercise from time to time to turn Haskell functions into one liner. Who knows, you can learn something!
You currently have
fun 1 = 0 fun n | even n = n + fun (n `div` 2) | otherwise = fun (3 * n + 1)
You can always convert an expression using protective devices to if
fun 1 = 0 fun n = if even n then n + fun (n `div` 2) else fun (3 * n + 1)
You can always convert a series of pattern matches into a case expression:
fun n = case n of 1 -> 0 _ -> if even n then n + fun (n `div` 2) else fun (3 * n + 1)
And finally, you can convert the case expression to an if chain (in fact, in the general case, an argument to your function will require an Eq instance, but since you use Integer , it doesnโt matter.
fun n = if n == 1 then 0 else if even n then n + fun (n `div` 2) else fun (3 * n + 1)
I think you will agree that this is much less readable than where you started.
source share