Rewrite Erlang compilation using foldSeq