-- CPSC 312 2024 - Assignment 3 Q3 solution
-- Copyright D. Poole, 2024. Do not redistrubute

-- splitsep (==',') "3,5,"  => ["3","5",""]
splitsep sep [] = [[]]
splitsep sep (h:t)
    | sep h = []: splitsep sep t
    | otherwise = ((h:w):rest)
                where w:rest = splitsep sep t

--  Some example queries to try:
-- splitsep even [1,3,4,5,7,9,8,8,55,45]
-- splitsep (==',') "comma,separated,list,as,in,a,csv,file"
-- splitsep (==',') "csv,,with,missing,elts,,,"
-- splitsep (`elem` " ,.?!") "What? is this thing? ... called Love."

readcsv filename =
  do
    file <- readFile filename
    return [splitsep (==',') line| line <- splitsep (=='\n') file]

-- try:
-- readcsv "test.csv"