3 ms·
The first example will lead to infinite recursion. There is no base case.
by philip-b 4y ago
The first example will lead to infinite recursion. There is no base case.
- bidirectional 4y agoUnder Haskell's evaluation strategy `(fix f)` will not be evaluated until it is used, if the definition of `f` ignores its parameter under some scenario, then evaluation will terminate.
- vq 4y agofix :: (a -> a) -> a fix f = f (fix f) f :: [Int] -> [Int] f xs = 1 : map (*2) xs take 7 (fix f) ==> [1,2,4,8,16,32,64] Looks right to me.
- gpderetta 4y agoI think the trick is that Haskel is lazily evaluated. The Y combinator has a different formulation on strict languages.
- lupire 4y agoA general fixed point combinator cannot have a base case; it relies on the parameter to terminate the computation.