mardi 9 mars 2021

Ocaml : transform a pattern matching expression into if expression (if... then... else)

I'm trying to write this pattern matching recursion expression

let rec drop_last l =
match l with
| [] -> []
| [_] -> [] 
| h::t -> h :: drop_last t ;;

as an 'if statement' recursion expression. I've started doing the following :

let rec drop_last2 l =
if l = [] then [] else 
if l = [_] then [] else
l = List.hd::List.tl then List.hd::drop_last2 (List.tl l);;

However, I'm getting a syntax error from the compiler. Could someone please tell me how should I modify this if statement into something correct?

Aucun commentaire:

Enregistrer un commentaire