Skip to content

Instantly share code, notes, and snippets.

@yuroyoro
Created February 6, 2013 11:41
Show Gist options
  • Select an option

  • Save yuroyoro/4722086 to your computer and use it in GitHub Desktop.

Select an option

Save yuroyoro/4722086 to your computer and use it in GitHub Desktop.
Haskellの練習でLTSVパースするヤツ
import qualified Data.Map as M
import Data.List.Split
type Field = (String,String)
type Fields = M.Map String String
main = do cs <- getContents
mapM_ showTree' $ parse cs
showTree' :: Fields -> IO()
showTree' = putStr . M.showTree
parse :: String -> [Fields]
parse = map parseLTSV . lines
parseLTSV :: String -> Fields
parseLTSV = M.fromList . map splitField . splitOn "\t"
splitField :: String-> Field
splitField = dropEqual . break (==':')
where dropEqual (a, ':':b) = (a,b)
dropEqual (a,b) = (a,b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment