开发者

Haskell -> After parsing how to work with strings

开发者 https://www.devze.com 2023-02-01 01:08 出处:网络
Hello after doing the parsing with a script in Haskell I got a file with the \'appearance\' of lists of strings. However when I call the file content with the function getContents or hGetContents, ie,

Hello after doing the parsing with a script in Haskell I got a file with the 'appearance' of lists of strings. However when I call the file content with the function getContents or hGetContents, ie, reading the contents I get something like: String with lines (schematically what I want is: "[" aaa "," bbb "" ccc "]" -> ["aaa", "bbb" "ccc"]). I have tried with the read function but without results. I need to work with these lists of strings to concatenating them all in a single list.

I'm using the lines function, but I think it only 'works' one line at a time, doesn't it? What I need is a function that verify if an element of a line is repeted on other line. If I could have a list of a list of strings it could be easier (but what I have is a line of a string that looks like a list of st开发者_StackOverflowrings) Regards Thanks.


I have tried with the read function but without results

Just tested, and it works fine:

Prelude> read "[\"aaa\",\"bbb\",\"ccc\"]" :: [String]
["aaa","bbb","ccc"]

Note that you need to give the return type explicitly, since it can't be determined from the type of the argument.


I think the function you are looking for is the lines function from Data.List (reexported by the Prelude) that breaks up a multi-line string into a list of strings.


in my understanding, what you can do is

create a function that receives a list of lists, each list is a line of the entire string, of the argument passed in, and checks if a element of a line occurs in other line.

then, this function passes the entire string, separated by lines using [lines][1].

0

精彩评论

暂无评论...
验证码 换一张
取 消