mercredi 7 octobre 2020

List of integers to Float in F#

I just started working with FSharp and have this homework, hope anyone can help me. I have to write a program that takes a list of integers and returns a float. It should be calculated by continued fraction. So if the int list is [4; 5; 6] The float will be calculated by: 4 + (1 / (5 + 1/6) )

The function has to be recursive. I have written the following:

let rec fractionDecimal (numberlist : int list) : float =
  match numberList with
    |[] -> 0.0
    | x :: y -> x + 1.0 / fractionDecimal y

it doesn't work because (fractionDecimal y) float doesn't match the type int. Do you have any suggestions how to solve the problem or what to do to get my code to work? thanks in advance

Aucun commentaire:

Enregistrer un commentaire