Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How does \n work in Char lists in haskell

right now I have a String equal to "...\n...\n...". In my code I want to write this as a list (like ['a','b','c']), but how would this work with the \n? I checked in ghci if string == ['.','.','.','.','.','.','.','.','.'] and it said no, so does anyone know how I would write the \n’s in a Char list, thank you.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

A String is a list of Characters, so "foo" and ['f', 'o', 'o'] are exactly the same.

For a new line character '\n' [wiki] you can escape this, so your string "...\n...\n..." is equivalent to:

['.', '.', '.', '\n', '.', '.', '.', '\n', '.', '.', '.']

You can thus for example filter with filter ('\n' /=) some_string to filter out new line characters from a String.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading