📜 ⬆️ ⬇️

F # is not lazy: (

Here is the code:

 let rec y func tracker args =
     func args (Y func tracker (tracker args))
    
 let fib N = (fun (x, y) -> x) (Y 
     (fun N (prev, pprev) -> if N = 1 then (1, 0) else (prev + pprev, prev)) 
     (fun N -> N - 1)
     N)
        
 let main =
     let value = fib 10
     System.Console.WriteLine (value)
     System.Console.ReadKey ()

When compiling and running it, instead of fully calculating the first lambda function with N = 0, the hell is counting on the useless values ​​of N, less than zero!

What's happening? Maybe “laziness” can somehow be forced?

')

Source: https://habr.com/ru/post/57655/


All Articles