I can offer you some way to do this:
let decompose_int i = let r = i / 10 in i - (r * 10) , r
This function allows me to decompose an integer as if I had a list. For example, 1234 divided into 4 and 123 . Then we will cancel it.
let rec rev_int i = match decompose_int i with | x , 0 -> 10 , x | h , t -> let (m,r) = rev_int t in (10 * m, h * m + r)
The idea here is to return 10 , 100 , 1000 ... etc. to find out where to place the last digit.
What I wanted to do here was to process them, since I will be considering lists, decompose_int is the equivalent of List.hd and List.tl
source share