File: CSV.hs

package info (click to toggle)
bali-phy 4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 15,392 kB
  • sloc: cpp: 120,442; xml: 13,966; haskell: 9,975; python: 2,936; yacc: 1,328; perl: 1,169; lex: 912; sh: 343; makefile: 26
file content (20 lines) | stat: -rw-r--r-- 671 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
module Data.CSV ( read_csv, read_tsv )
    where

import Foreign.String
import Foreign.Vector
import Data.Foldable

mapToList f = map f . toList

foreign import bpcall "Data:read_csv" builtin_read_csv :: CPPString -> Char -> IO (EVector (EVector CPPString))

-- This gives the csv file as a list of rows
read_csv :: String -> IO [ [ String ] ]
read_csv filename = mapToList (mapToList unpack_cpp_string) <$> builtin_read_csv filename' ','
    where filename' = pack_cpp_string filename

read_tsv :: String -> IO [ [ String ] ]
read_tsv filename = mapToList (mapToList unpack_cpp_string) <$> builtin_read_csv filename' '\t'
    where filename' = pack_cpp_string filename