reset password
Author Message
AverageStudentX
Posts: 11
Posted 16:26 Nov 26, 2019 |

Any one here figured out how to do 4a? I am trying to figure this one out, although I don't even know if I did the other parts right (even with that guy's help, I don't trust myself.).

At this point I'll take any suggestions that might help. Even links to other, hopefully easier, haskell textbooks might help.

AverageStudentX
Posts: 11
Posted 16:46 Nov 26, 2019 |

Welp I figured out one of the many problems I ran into just now.

I guess Haskell does not like MS Excel sheets saved as CSV UTF-8 files, no idea what that is.

 

kcrespi
Posts: 12
Posted 18:23 Nov 26, 2019 |

Did you figure out how to approach the problem?
I was able to read the file into a String, then split the String into a [String] where every item in the [String] is all the info of a single student. I'm currently trying to make a function that takes a [String] and returns a [Students] but I'm not sure if this is the correct approach since I'm in a locked on how to execute it.

AverageStudentX
Posts: 11
Posted 12:49 Nov 27, 2019 |

Being honest I have no idea what I am doing.

This is what I figured out so far. I used one of the last examples in lecture 10 to do the file reading.

I found out that Haskell does not like certain CSV file variations. One of them makes the language read extra numbers and characters into the info.

With that problem out of the way. The "main" block reads the file, but it reads it all in one line. Printing it shows that the student info fields

are separated by commas, and after each last field it follows a next line character. I have no idea how to approach this problem.

I have to figure out how to handle the fields separated by commas, and how to handle the info for each student separated by next line characters.

llucero2
Posts: 1
Posted 14:01 Nov 27, 2019 |

I was able to read the file using "readFile". "putStrLn" should output the contents one line at a time. ie

" John, Smith, Comp Sci, 24 "

"Jack, Daniels, History, 29 " 

I'm stuck here. I know I need to write a function that takes this data and turns it into a list of students. 

msargent
Posts: 519
Posted 14:21 Nov 27, 2019 |

Think about how you would make a single student with the appropriate information. Then apply to multiple students.

kcrespi
Posts: 12
Posted 15:07 Nov 27, 2019 |

So I was able to think of a viable solution. 
I read the file, create a function that takes a String and returns a [String] that recursively iterates the String and stores a chuck of the String each time a Char in the String == "/n". This will give you an [String] in which each item is a line of the original String, then do the same with the comas, make a function that takes a [String] and returns a [[String]] that iterates the list and each item then store a word when a Char in the String =="," This will give you a [[String]] in which each List in the List is the info of each Student, then make a function that takes a [[String]] and returns a [Student]
(I know its not the best solution, but is the only one I was able to come up with)

For the function that splits Strings, I used the words function on Prelude as example. (https://www.haskell.org/onlinereport/standard-prelude.html)  replacing the Bool result of "Char.isSpace" with the (==",") or (=="/n")

Last edited by kcrespi at 15:14 Nov 27, 2019.
msargent
Posts: 519
Posted 16:44 Nov 27, 2019 |

An idea, go through the string in a line recursively and replace the commas with spaces, then use words. Use foldr to build the string as you go.

Last edited by msargent at 16:47 Nov 27, 2019.