Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Solution
- // Number in List: 4 -> task 5
- // In this sample, the goal was to compute the length of the list
- // Method 1: Library Function
- let sum1 = List.sumBy(fun x -> x*x)
- // Method 2: Recursion
- let rec sum2 = function
- | [] -> 0
- | h::t -> sum2(t) + h*h
- // Method 3: Tail Rec
- let sum3 =
- let rec sum3' acc = function
- | [] -> acc
- | h::t -> sum3' (acc + h*h) t
- sum3' 0
- let ar = [1..10]
- printfn "Example:\nSum1: %i Sum2: %i Sum3: %i" (sum1 ar) (sum2 ar) (sum3 ar)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement