let rec longAddWithoutCarry = function [], x -> x | x, [] -> x | hd1 :: tl1, hd2 :: tl2 -> hd1 + hd2 :: longAddWithoutCarry (tl1, tl2) let longAdd (lst1, lst2) = let rec helper = function [], [], 0 -> [] | [], [], carry -> [carry] | [], hd :: tl, carry -> (hd + carry) mod 10 :: helper ([], tl, (hd + carry) / 10) | hd :: tl, [], carry -> (hd + carry) mod 10 :: helper (tl, [], (hd + carry) / 10) | hd1 :: tl1, hd2 :: tl2, carry -> (hd1 + hd2 + carry) mod 10 :: helper (tl1, tl2, (hd1 + hd2 + carry) / 10) in helper (lst1, lst2, 0) let multAll prod lst = List.map (fun x -> x * prod) lst let timesTen lst = 0 :: lst let rec longMult = function [], num2 -> [] | hd :: tl, num2 -> longAdd (multAll hd num2, timesTen (longMult (tl, num2)));; longMult ([3; 2; 1], [2; 1]);; longMult ([2; 1], [3; 2; 1]);; longMult ([9; 7; 6; 5; 4; 3; 2; 1], [8; 1]);; longMult ([], [9; 9; 9; 9; 9; 9]);; longMult ([1], [9; 9; 9; 9; 9; 9]);; longMult ([1; 1; 1; 1; 1; 1; 1; 1; 1], [1; 1; 1; 1; 1; 1; 1; 1; 1]);; let rec forever a = forever a;;