Haskellized str/int encoding and decoding