0

["6","","[[1,2,3,4,5,6],[7,8,9,10,11,12],[13,14,15,16,17,18],[19,20,21,22,23,24],[25,26,27,28,29,30],[31,32,33,34,35,36]]"] I must get from this 6 and [[1,2,3,4,5,6],[7,8,9,10,11,12],[13,14,15,16,17,18],[19,20,21,22,23,24],[25,26,27,28,29,30],[31,32,33,34,35,36]] I read from file in file it look

6. [[1,2,3,4,5,6],[7,8,9,10,11,12],[13,14,15,16,17,18],[19,20,21,22,23,24],[25,26,27,28,29,30],[31,32,33,34,35,36]].

I tried with map and read to convert string but it wasnt working. sry for english

1
  • You really need to be more specific about what you have tried. "with map and read" does not tell us that much. Commented Jun 18, 2011 at 15:57

1 Answer 1

2

The problem with using map and read directly is, that your list elements don't all have the same types. The first element is (or better: should be converted to) an Int, the second an empty list and the third an `[[Int]].

To convert the first element of the list into an Int, you can say something like read $ head xs :: Int, where xs is your list of strings.

The second element cannot be directly converted by read, since an empty string will result in an exception (Prelude.read: no parse).

To convert the third element, which is a list of lists of integers, you can simply say something like read $ xs !! 2 :: [[Int]].

This is not safe or elegant, but if your input always has this structure it should work.

Sign up to request clarification or add additional context in comments.

1 Comment

It dont worki with IO string but with string yes. Atm i need conversion from Io to string

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.