I am trying to read a file. The title is read correctly, but when I try to read the cast (actor) it seems that it does not have to stop and search. Is there any mistake in analyzing the percing or chairs to actors? Type type = type = string type actor = string type cast = [actor] type year = int type fan = string type fan = [fan] type period = (year, year) type
= Database = [movie] Type movie = (title, cast, year, fan)
- Parsing methods to read the file
Parcelons :: [String] - & gt; Film Parcelains list = (list !! 0, parsectors (drop 1 list), read (list 2!), Parsectors (drop 3 list)) parsfains :: [string] - & gt; Fan parsfence [] = [] parsfans list | Length list & gt; 0 = [(list !! 0)] ++ Parsefance (drop 1 list) parseActors :: [string] - & gt; Cast Parsectors [] = [] Parsactors list | Length list & gt; 0 = [(list !! 0)] ++ parseActors (drop 1 list) parseChars :: string - & gt; String - & gt; [String] Pars Chairs [] _ = [] Pars Chars (X: X) string coat | X == ',' = [stringCount] ++ Pars Chas X "" | | Otherwise = (Pars Chas x (string quote ++ [x])) Pars all :: [string] -> [Movie] Pars all [] = [] Pars all (x: x) = parcelenus (purse char x ""): (pars all xs)
and I get this error < / P>
| Gunman | | | Idris Alba, Sean Penn, Javier Bardem, 2015, Gary, Dave, Jo, Kevin, | * Main> *** Exception: prelude.read: no parse
This is my text file
The Gunman, Idris Alba, Sean Penn, Xavier Bard, Jo, Gary, Kevin, Olga, Liz, The Dark Knight, Christian Bale, Heath Ledger, Bard, 2015, Gary, Dave, Zoe, Kevin, Emma, Shoshank Redemption, Tim Robbins, Morgan Freeman, Bob Gunton, Aaron Echert, 2008, Zoe, Heidi, Jo, Emma, Liz, Sam, Olga, Kevin, Tim, Institution, Leonardo DiCaprio, Ellen Page, 2010, Jo, Emma, J. , Olga, Kevin,
parsectors :: [string] - & gt; ; Cast Parsectors [] = [] Parsactors list | Length list & gt; 0 = [(list !! 0]] ++ parseActors (drop 1 list)
Have you tried to see what this does?
GHCi> ParseActors ["one", "two", "three"] ["one", "two", "three"]
what you have done It is a very complex version:
Parsactors :: [String] -> Cast Paras Actors list = list
Similarly,
parsfains :: [string] -> fan parsefance [] = [] parsfains list | length list & gt; 0 = [(list !! 0]] ++ parseFa Ns (drop 1 list)
This code is similar to parseActors
, you have just changed the name parseFans
and the type of result < Code> fan . It behaves in the same way:
parseFans :: [string] -> list of fans = list
I am going to move forward and now I am ignoring the above. Instead, take parsa chairs
for the spin.
ghci & gt; Ah, such a function that actually parses me, I'm not sure how you work it. "A, two, three," "one", "two", "three"]
Expect to do, but I think it is working as expected.
I want to draw your attention on this part of this parse line:
reading (list !! 2)
You are trying to do this and are using the year to get it. And this is what is throwing the error: preload. Read: no parse
. Note that this tells you that the use of prelude.read
is a criminal.
Okay. Let's take the first movie and run it through some of this code.
ghci & gt; Gunmen = "The Gunman, Idris Alba, Sean Penn, Javier Bardem, 2015, Gary, Dave, Zoe, Kevin, Emma," Gachi & GT; List = Purs Charge Gunman "" GCA & gt; List ["The Gunman", "Idris Alba", "Sean Penn", "Javier Bardem", "2015", "Gary", "Dave", "Zoe", "Kevin", "Emma"] ghci & gt; List !! 2 "Seine Pen"
Notice how list !! 2 year is not your problem is ok, one of them, anyway.
Then learn the lesson:
- Use the interactive prompt (ghci) to test the fragment of your code and make sure that the way you Expect.
- Filtering error messages, they can often give clues about what is wrong with your code.