4 ms·
Ah! My favourite Haskell discussion. So, consider these two programs, the first in Haskell: main :: IO () main = do foo foo foo :: IO
by tome 10mo ago
Ah! My favourite Haskell discussion. So, consider these two programs, the first in Haskell:
main :: IO ()
main = do
foo
foo
foo :: IO ()
foo = putStrLn "Hello"
and the second in Python:
def main():
foo()
foo()
def foo():
print("Hello")
For the Python one I'd say "I/O is done inside `foo` before returning". Would you? If not, why not? And if so, what purpose does it serve to not say the same for the Haskell?
- adastra22 10mo agoMy Haskell is rusty enough that I don’t know the proper syntax for it, but you can make a program that calls foo and then throws away / never uses the IO computation. Because Haskell is lazy, “Hello” will never be printed.
- tome 10mo agoYou can do this main = do let x = foo putStrLn "foo was never executed" but you can also do this def main(): x = foo print("foo was never executed") What's the difference?