I have just started with F# and functional programming. I want to know how I can make a function taking a tuple where I define that the first value have to be a string, instead of the standard int.
Example:
A function which replicates a string, s, n times and returns it. What i have right now is this:
let rec pow2 = function
| (s:string,0) -> ""
| (s:string,n) -> s + pow2(s,n-1)
This works, but I think that there is a better way than defining s:string every case.
(I know String.replicate, this is not for the sake of the effect, but learning)
In fact, no type annotations are required here. The
""return value in the the first pattern match is a sufficient enough hint for the compiler: