vendredi 9 décembre 2016

Find common chars in 2 list Ocaml

I am new with Ocaml, my problem is: i have 2 char lists, i want to put in another list the common character of the 2 lists (error. My base code is this (error in the "check ->hd1<- tl2"):

let rec check list1 list2 = match list1, list2 with
| hd1::tl1, hd2::tl2 when hd1 = hd2 -> hd1
| hd1::tl1, hd2::tl2 ->  check  hd1 tl2
| [],[] -> ' '
| _::_,_ -> ' '
| [],_::_ -> ' ';;

check ['l'; 'e'; 'l'; 'l'; 'o'] ['h'; 'e'; 'o'];;

my biggest problem is, how to fix a list and go forward the other? and another problem is to delete, at the moment, a character when i find it. (example: list1= "hello" list2="helo" when the first "l" was found, list2="heo" final_list-->"helo").

i have to learn better this concept of pattern

thank you for your future answers

Aucun commentaire:

Enregistrer un commentaire