vendredi 12 février 2021

F# pattern matching with string

let rec matchs str currList =
    match currList with 
    | [] -> []
    | (str, _) as hd :: tl -> hd :: matchs str tl
    | _::tl -> matchs str tl

I have my function here, and when i try to execute it with this line:

matchs "A" [("A",5); ("BB",6); ("AA",9); ("A",0)];;

This is the given output

val it : (string * int) list = [("A", 5); ("BB", 6); ("AA", 9); ("A", 0)]

I am not understanding why its not giving me only the tuples matching "A"

eventually i would want my output to be

val it : int list = [0; 5]

Aucun commentaire:

Enregistrer un commentaire