Created
April 22, 2014 23:59
-
-
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.)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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