Challenge 3: Does Either Language's main Get a Free Pass? — Possible Solution ==================================================================== // Java's `public static void main(String[] args)` genuinely gets a // free pass from Java's own type system -- there is no mechanism in // Java's types at all that distinguishes "a method that only computes // a value" from "a method that reads files, opens sockets, and prints // to the console." main is free to do absolutely anything, and // nothing about its signature says so one way or the other -- the // SAME is true of every other Java method too, which is exactly why // there's nothing special about main specifically getting a pass: no // Java method is ever tracked for side effects, main included. // // Haskell's `main :: IO ()`, by contrast, does NOT get a free pass -- // and that's the entire point of this chapter. main's type explicitly // declares that it may perform IO, exactly the same way any other // IO-performing function's type would. There is no special, untracked // "root" function in Haskell that's allowed to silently do IO without // its type saying so. If main's own type were declared as something // that claimed to be pure (which isn't actually possible for a real // program that needs to interact with the world, but hypothetically), // GHC would refuse to compile a main that tried to call putStrLn or // getLine inside it, exactly the same rejection any other pure // function calling IO code would get. // // The real difference isn't that Haskell has SPECIAL rules for main -- // it's that Haskell has NO exceptions to its one general rule (every // side-effecting computation is tracked in its type), while Java has // no such rule to begin with, for main or for anything else. WHY THIS WORKS AS AN ANSWER ------------------------------ This correctly identifies that Java's main isn't specially exempt -- NOTHING in Java is tracked for side effects, main included -- while Haskell's main is genuinely bound by the same IO-tracking rule as every other function, matching the chapter's own "no trusted root" claim precisely.