I'm trying to understand why the first main
does not terminate when c
is not valid, while the second terminates. From the description here
main
is just an unevaluated thunk, and executing
it is just building up the data structure. I'm trying to apply the same principle here and see why the first main does not terminate. If someone can help me understand this part, or give me pointers to understanding this would be great. Apart from this, why is GHCI not able to recognize this as TCO ? does is not fit the definition?
main = loop
where
loop = do
c <- getChar
case valid c of
Nothing -> return ()
Just b -> print b
print c
loop
> main :: IO ()
> main = loop
> where
> loop = do
> c <- getChar
> case validate c of
> Nothing -> return ()
> Just b -> do
> print b
> loop
Thanks.