ocaml-programming

Simple OCaml programs
git clone git://git.laack.co/ocaml-programming.git
Log | Files | Refs | README

commit ed2c52b3d83ec9f986c10183b7934dacc94d3164
parent c52cdb298fd056ad696e14ec98a4c6a268bee8f5
Author: Andrew Laack <andrew@laack.co>
Date:   Sun,  6 Sep 2026 11:50:29 -0500

Append list using cons + recursion

Diffstat:
Ach3/follow-along/list_append.ml | 12++++++++++++
1 file changed, 12 insertions(+), 0 deletions(-)

diff --git a/ch3/follow-along/list_append.ml b/ch3/follow-along/list_append.ml @@ -0,0 +1,12 @@ +let rec append l1 l2 = match l1 with + | [] -> l2 + | h :: t -> h :: append t l2 + +let rec print_list xs = match xs with + | [] -> () + | h :: xs' -> (print_int h); print_newline (); (print_list xs') + +let (l1 : int list) = [12340;2] +let (l2 : int list) = [10;24;123;12340] +let (l3 : int list) = append l1 l2 +let () = print_list l3