Totality function with IO

After reading Professor Yorgi lecture in IO, is the following function considered complete?

Prelude> let fx = return $ error "44" :: IO Int

I understand that a complete function completes and returns a value for each input.

However, since Haskell separates the evaluation and implementation of IO , I am not sure how comprehensiveness applies to f .

+6
source share
1 answer

The function f indeed complete. It returns a value for any input. In particular, it produces the same value each time.

The value is an IO action that, when executed, is likely to terminate the program if not executed in a context that might deal with the error. But this does not matter, since just applying f does not trigger the IO action.

Here is an example program that uses f :

 main = putStrLn $ show $ length $ map (f$) [1,2,3] 

and he should print

 3 
+2
source

Source: https://habr.com/ru/post/1012597/


All Articles