Skip to content

Instantly share code, notes, and snippets.

@quchen
Created April 22, 2014 23:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quchen/11198459 to your computer and use it in GitHub Desktop.
Save quchen/11198459 to your computer and use it in GitHub Desktop.
Awful Haskell from http://www.reddit.com/r/haskell/comments/23pf6v/just_a_little_decider/, copied from the paste at http://lpaste.net/5303930864168599552. (I am not the author of this.)
import qualified Data.Set as S
import System.IO.Unsafe
import System.Directory
import System.Environment
import Control.Exception
import Data.List
newtype Song = Song String
deriving (Show, Read, Eq)
instance Ord Song where
compare (Song a) (Song b) = unsafePerformIO $ do
print "Which Song do you like better?"
print $ "1. " ++ a
print $ "2. " ++ b
choice <- try readLn :: IO (Either SomeException Int)
case choice of
(Right 1) -> return LT
(Right 2) -> return GT
_ -> do
print "invalid input, try again"
return $ compare (Song a) (Song b)
main = do
[path] <- getArgs
c <- getDirectoryContents path
let songs = map Song $ filter (".gp5" `isSuffixOf`) c
print $ S.toAscList $ S.fromList songs
print "done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment