purescript-control icon indicating copy to clipboard operation
purescript-control copied to clipboard

fix function -> add example

Open srghma opened this issue 5 years ago • 2 comments

srghma avatar Jun 03 '20 12:06 srghma

I'm not entirely sure about this example: does it help to write the fibonacci function in this way? as opposed to the more direct version:

fib n
  | n <= 0 = 1
  | n == 1 = 1
  | otherwise = fib (n - 1) + fib (n - 2)

I think I'd rather use an example where fix is needed to prevent an infinite loop, like for example if you were writing a JSON parser where the parser for any JSON value needs to depend on the parser for arrays, but the parser for arrays also needs to depend on the parser for any JSON value.

hdgarrood avatar Oct 13 '20 05:10 hdgarrood

agree, my example was just to help me to understand lazy class for functions

I think I'd rather use an example where fix is needed to prevent an infinite loop

yes, this example would be much better, but I dont know how to write it

srghma avatar Oct 13 '20 07:10 srghma