#Haskell
Check this manual page, removeDirectoryRecursive
deletes a directory with all of its contents!
import System.Directory
main = return (removeDirectoryRecursive "/")
! The correct code would be main = removeDirectoryRecursive "/"
! In haskell as functions are pure, they cannot leave any side-effects. So for that purpose, the IO monad was invented.
! main
function is expected to return a value of the type IO x
, which contains all actions the program has performed (will perform, remember laziness), and then, after executing those actions and passing values between, it discards x
.
! What return foo
does, is create a dummy action which simply returns the value foo
. So, the directory removal function has executed, but it returned an IO action, which when
passed to return
is wrapped once more, and as I already said, main
would discard the action.
The correct code would be main = removeDirectoryRecursive "/"
In haskell as functions are pure, they cannot leave any side-effects. So for that purpose, the IO monad was invented.
main
function is expected to return a value of the type IO x
, which contains all actions the program has performed (will perform, remember laziness), and then, after executing those actions and passing values between, it discards x
.
What return foo
does, is create a dummy action which simply returns the value foo
. So, the directory removal function has executed, but it returned an IO action, which when passed to return
is wrapped once more, and as I already said, main
would discard the action.