lundi 21 décembre 2020

OCaml function apparently works but does not return the expected result

Who can help? I am a beginner in OCaml, I am trying to perform an action of unpacking sets. Having a set [(1, 4); (2, 5); (3, 6)] I want to get the exit [(1,2,3), (4,5,6)]. I am using a script that I tested with Haskell and it worked, but in OCaml, it does not show the result. Where am I going wrong? I could not figure out where my mistake is. Thx.

let fst num1 num2 =
  match num1, num2 with
  | (x, y) -> x;;

let snd num1 num2 =
  match num1, num2 with
  | (x, y) -> y;;

let rec dcp_base list1 list2 list3 =
  match list1, list2, list3 with
  | (xs, ys, []) -> (xs, ys)
  | (xs, ys, z :: zs) -> dcp_base (xs @ [fst z]) (ys @ [snd z]) zs;; 

let descompact list =
  match list with
  | [] -> ([], [])
  | xs -> dcp_base [] [] xs;;

Aucun commentaire:

Enregistrer un commentaire