Last active
December 29, 2015 03:19
-
-
Save jrm2k6/7607022 to your computer and use it in GitHub Desktop.
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
| {-# LANGUAGE OverloadedStrings #-} | |
| import qualified Data.Text as T | |
| import Data.Char (isDigit) | |
| import System.IO | |
| import Data.List (partition, intersperse) | |
| import System.Environment (getArgs) | |
| main = do | |
| args <- getArgs | |
| content <- readFile(args !! 0) | |
| let l = lines content | |
| let lf = filter (\x -> length x > 0) l | |
| mapM_ (putStrLn . arrange) lf | |
| tokens :: String -> [String] | |
| tokens [] = [] | |
| tokens s = | |
| case break(== ',') s of | |
| (x, []) -> [x] | |
| (x, _:xs) -> x:tokens xs | |
| untokens :: [String] -> String | |
| untokens l = concat . intersperse "," $ l | |
| isANumber :: String -> Bool | |
| isANumber = all isDigit | |
| -- ["i", "am", "the", "12", "light"] | |
| separate :: [String] -> ([String], [String]) | |
| separate l = partition (not . isANumber) l | |
| generateSentence :: ([String], [String]) -> String | |
| generateSentence (xa, []) = untokens xa | |
| generateSentence ([], xb) = untokens xb | |
| generateSentence (xa, xb) = untokens xa ++ "|" ++ untokens xb | |
| arrange :: String -> String | |
| arrange = generateSentence . separate . tokens |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment