First of all, you use the let keyword when you are in GHCi because you are in the IO monad. Usually you do not need to define a function in the source code. For example, you might have a file called "MyProgram.hs" containing:
addUserName = do putStrLn "Please enter the username:" addName <- getLine appendFile "UserList.txt" ("\n" ++ addName)
Then in GHCi you enter:
ghci> :l MyProgram.hs ghci> addUserName
(This is: l for: load, not a number). In fact, you can define a function in GHCi, but it's a bit of a pain if it's not single-line. This will work:
ghci> let greet = putStrLn "Hello!" ghci> greet Hello!
source share