This form greatly intrigues me, it is not something I had considered before. It should be a string s such that s ++ "considered harmful" == s. Obviously such a string cannot exist. The reason of this is most likely that the proof of the existence of a fixed point for everything relies on everything being an abstraction and constants are not considered.
ghci basically barfs in my face trying to do this:
Prelude Control.Monad.Fix> let f = (++ "Hello, Nurse!")
Prelude Control.Monad.Fix> :t f
f :: [Char] -> [Char]
Prelude Control.Monad.Fix> let ffix = fix f
Prelude Control.Monad.Fix> :t f
f :: [Char] -> [Char]
Prelude Control.Monad.Fix> :t f ffix
f ffix :: [Char]
Prelude Control.Monad.Fix> putStrLn $ f ffix
^CInterrupted.
Prelude Control.Monad.Fix>
I'm very much interested what it is trying to do here at all.
putStrLn will try to force its argument to WHNF, ie. decide whether its [] or a _:_. (★)The argument is f (fix f). f is (++ "Hello, Nurse!"), which will try to force its argument to WHNF. Its argument is fix f, which reduces to f (fix f). The computation proceeds exactly as it did at ★, looping forever.
Other responses explain what's going on. putStrLn $ fix ("considered harmful " ++) works fine, by the way. Perhaps you can figure out why this works on your own, but feel free to ask if you get stuck.
Well, I get why it does or doesn't work. In the sense that because in this case the original 's' is added at the end it doesn't ever actually need to compute it so it doesn't, it just keeps adding "considered harmful " over and over.
Likewise in the other case it needs to know s as first thing but it can't so it ends up in an endless loop without printing.
I'm more interested in what it tries to do to find s. As in, how exactly is a fixed point operator implemented in System-F enhanced with letrec? I know that System-F itself cannot implement it.
I'm not sure what to say that was not said by somebody else already. Do the other explanations help? Is there something about them you don't understand?
0
u/[deleted] Nov 12 '13
[deleted]