Recursive function basics
In this chapter, I want to introduce you to the basics of recursive functions, leaving more detailed consideration for the more advanced contexts. At this point, I want to show how the F# default treatment of functions as non-recursive differs from a forced one when the function is explicitly declared recursive using the let
binding modifier, rec
.
Take a look at the following far-fetched snippet (Ch3_8.fsx
):
let cutter s = let cut s = printfn "imitator cut: %s" s let cut (s: string) = if s.Length > 0 then printfn "real cut: %s" s cut s.[1..] else printfn "finished cutting" cut s
The cutter
function here provides a non-empty string that's supposed to cut it from the left-hand side, symbol by symbol, until the argument is ...
Get F# 4.0 Design Patterns now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.