Need help to returns result

hi everyone,

i did this exercice:
‘’’ (*listes_paires l : prend en argument la liste de listes l et retourne une copie de l dans laquelle les listes de longueur impaire on été “doublées”. Doublée ici signifie qu’une liste a est remplacée par a@a (concaténation de a avec elle-même). Exemple

listes_paires [; [1];[1;2];[1;2;3];;[5;4;3;2;1]];;
retourne ceci:

[; [1; 1]; [1; 2]; [1; 2; 3; 1; 2; 3]; ; [5; 4; 3; 2; 1; 5; 4; 3; 2; 1]] - int List*)

let rec listes_paires l = match l with
| x :: r → if length x mod 2 = 0 then (x :: (listes_paires r))
else ((x@x):: (listes_paires r));;
but i don’t know how see the result on console on replit
normaly i have to put a test function on


You can write your OCaml code in a file named, compile it with the command ocamlc -o main.exe and run it with the command ./main.exe, assuming you are using a Linux-like system. If that does not work for you, you’ll have to give us more info on your OS.

in case this might be of interest to you, there is also an OCaml discord server that you can join here : OCaml
There are a #beginners and a #débutants channel where you can ask questions in English or French, and maybe get more interactive help.

For such a short code snippet, if you use a REPL / toplevel (I advise installing and using utop), you can simply paste your code in it.
If I do so, for listes_paires [[];[1];[1;2]];; for instance, I get

- : int list list =
[[]; [1; 1]; [1; 2]]

PS : You are not using backticks (`) to format your code : you have a preview on the right to see how it renders, and you can edit your post to change to backticks instead of single quotes.

To run your code on a browser you can also use one of the dedicated web-toplevel like the one of the official website (with Merlin!) or the learn-ocaml one which also features a number of exercises.

thanks you, this website is very nice. i will try it

1 Like

Maybe you are trying to use with the OCaml template? I was able to get a minimal example going.

  1. erase and edit the file in bin/
  2. switch to the “Shell” tab (top right)
  3. run using the command dune exec bin/main.exe.

yes i know that. have a nice day