After reading over Prof. Yorgey's lecture on IO, is the following function considered to be total?
Prelude> let f x = return $ error "44" :: IO Int
I understand that a total function terminates and returns a value for every input.
However, since Haskell separates the evaluation and execution of IO
, I'm not sure how totality applies to f
.
The function f
is indeed total.
It returns, for any input, a value. Specifically, it produces every time the same value.
The value happens to be an IO action, that, when executed, will probably terminate the program, unless run in a context that can deal with the error. But this doesn't play a role, since merely applying f
does not run the IO action.
Here is an example program that uses f
:
main = putStrLn $ show $ length $ map (f$) [1,2,3]
and it should print
3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With