-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.hs
32 lines (27 loc) · 913 Bytes
/
Main.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Control.Applicative ((<$>))
import qualified Data.Text as T
import qualified Data.Text.IO as T
import System.Environment (getArgs)
import System.Exit (exitFailure)
import Megahaskhal (Brain, getWords, loadBrainFromFilename)
import Megahaskhal.Reply (generateReply)
die :: T.Text -> IO ()
die s = T.putStrLn s >> exitFailure
main :: IO ()
main = do
args <- getArgs
case args of
[filename] -> do
loadBrainFromFilename filename >>=
maybe (die "Unable to load from file.") runHal
_ -> die "Pass in a file name for the brain."
runHal :: Brain -> IO ()
runHal brain = do
T.putStrLn "Enter text: "
phrase <- getWords <$> T.getLine
print phrase
reply <- generateReply brain phrase
print reply
runHal brain