I have a function in which the marked line is a conjunction involving a recursive call. Since the conjunctions work, if h1 <> h2 , then the recursive call will not be made. But if the call is completed, then the compiler will still refuse and execute a whole bunch of unions over the true values? Or will he overcome this unnecessary step?
In other words, is a recursive function efficient?
let isExtensionOf<'A when 'A : equality> (lst1 : list<'A>) (lst2 : list<'A>) : bool = let rec helper (currLst1 : list<'A>) (currLst2 : list<'A>) : bool = match currLst1, currLst2 with | h1 :: _, [] -> false | [], _ -> true | h1 :: t1, h2 :: t2 -> (h1 = h2) && (helper t1 t2)
Yes, I know that the highlighted line should be written if h1 = h2 then helper t1 t2 else false . But I'm just curious.
Thanks in advance.
recursion tail-recursion f #
Shredderroy
source share