module Main where

{- 
   This program shows how to use the Text.Yahoo.RelatedSuggestion
   module.  Query strings are read in on stdin, sent you Yahoo, and the
   results displayed on stdout.  Using the SpellingSuggestion module
   is similar.
-}

import System.Exit (exitWith, ExitCode(..))
import Text.Yahoo.RelatedSuggestion (relatedSuggest)
import Text.Yahoo.Types

buildQueryRS queryString = 
  RSQuery "YahooDemo" queryString 3

doQuery q = do
  rs <- relatedSuggest q
  case rs of
    (Left e) -> return $ "Error: " ++ fst e
    (Right rs') -> return $ unwords rs'

main = forever $ do
  l <- getLine
  case l of
    (':':'q':cs) -> exitWith ExitSuccess
    q -> do r <- (doQuery . buildQueryRS) q
            putStrLn r

forever a = a >> forever a