Haskell: Convert String representation of Integer List of Lists to Integer List of Lists
I have a file that contains a list of lists,
namely [[39, 40, 1], [-39, -40, 1], [-39, 40, -1], [1, 41, 2], [-1, -41, 2], [-1, 41, -2], [2, 42, 3], [-2, -42, 3], [-2, 42, -3], [3, 43, 4], [-3, -43, 4], [-3, 43, -4], [4, 44, 5], [-4, -44, 5], [-4, 44, -5], [5, 45, 6], [-5, -45, 6], [-5, 45, -6], [6, 46, 7], [-6, -46, 7], [6, -46, -7], [7, 47, 8], [-7, -47, 8], [7, -47, -8], [-7, 47, -8], [8, 48, 9], [8, -48, -9], [-8, 48, -9], [9, 49, 10], [-9, -49, 10], [9, -49, -10], [-9, 49, -10], [10, 50, 11], [10, -50, -11], [-10, 50, -11], [11, 51, 12], [-11, -51, 12], [11, -51, -12], [-11, 51, -12], [-12, -52, 13], [12, -52, -13], [-12, 52, -13], [-13, -53, 14], [13, -53, -14], [-13, 53, -14], [14, 54, 15], [-14, -54, 15], [14, -54, -15], [-14, 54, -15], [-15, -55, 16], [15, -55, -16], [-15, 55, -16], [16, 56, 17], [-16, -56, 17], [16, -56, -17], [-16, 56, -17], [17, 57, 18], [-17, -57, 18], [-17, 57, -18], [18, 58, 19], [-18, -58, 19], [18, -58, -19], [-18, 58, -19], [19, 59, 60], [-19, -59, 60], [-19, 59, -60], [20, 59, 60], [-20, -59, 60], [20, -59, -60], [-20, 59, -60], [21, 58, 20], [-21, -58, 20], [21, -58, -20], [-21, 58, -20], [22, 57, 21], [-22, -57, 21], [22, -57, -21], [-22, 57, -21], [23, 56, 22], [23, -56, -22], [-23, 56, -22], [24, 55, 23], [-24, -55, 23], [24, -55, -23], [-24, 55, -23], [-25, -54, 24], [25, -54, -24], [-25, 54, -24], [26, 53, 25], [-26, -53, 25], [26, -53, -25], [-26, 53, -25], [27, 52, 26], [-27, -52, 26], [27, -52, -26], [-27, 52, -26], [28, 51, 27], [-28, -51, 27], [-28, 51, -27], [29, 50, 28], [-29, -50, 28], [29, -50, -28], [-29, 50, -28], [30, 49, 29], [-30, -49, 29], [30, -49,-29], [-30, 49, -29], [31, 48, 30], [-31, -48, 30], [31, -48, -30], [-31, 48, -30], [32, 47, 31], [-32, -47, 31], [32, -47, -31], [-32, 47, -31], [33, 46, 32], [33, -46, -32], [-33, 46, -32], [34, 45, 33], [-34, -45, 33], [34, -45, -33], [-34, 45, -33], [35, 44, 34], [-35, -44, 34], [35, -44, -34], [-35, 44, -34],[36, 43, 35], [-36, -43, 35], [-36, 43, -35], [37, 42, 36], [-37, -42, 36], [37, -42, -36], [-37, 42, -36], [38, 41, 37], [-38, -41, 37], [38, -41, -37], [39, 40, -38], [-39, -40, -38], [39, -40, 38], [-39, 40, 38]]
I have figured out how to import the file but am having trouble converting it from a String -> [[Int]].
How would I go about do so?
haskell types
|
show 1 more comment
I have a file that contains a list of lists,
namely [[39, 40, 1], [-39, -40, 1], [-39, 40, -1], [1, 41, 2], [-1, -41, 2], [-1, 41, -2], [2, 42, 3], [-2, -42, 3], [-2, 42, -3], [3, 43, 4], [-3, -43, 4], [-3, 43, -4], [4, 44, 5], [-4, -44, 5], [-4, 44, -5], [5, 45, 6], [-5, -45, 6], [-5, 45, -6], [6, 46, 7], [-6, -46, 7], [6, -46, -7], [7, 47, 8], [-7, -47, 8], [7, -47, -8], [-7, 47, -8], [8, 48, 9], [8, -48, -9], [-8, 48, -9], [9, 49, 10], [-9, -49, 10], [9, -49, -10], [-9, 49, -10], [10, 50, 11], [10, -50, -11], [-10, 50, -11], [11, 51, 12], [-11, -51, 12], [11, -51, -12], [-11, 51, -12], [-12, -52, 13], [12, -52, -13], [-12, 52, -13], [-13, -53, 14], [13, -53, -14], [-13, 53, -14], [14, 54, 15], [-14, -54, 15], [14, -54, -15], [-14, 54, -15], [-15, -55, 16], [15, -55, -16], [-15, 55, -16], [16, 56, 17], [-16, -56, 17], [16, -56, -17], [-16, 56, -17], [17, 57, 18], [-17, -57, 18], [-17, 57, -18], [18, 58, 19], [-18, -58, 19], [18, -58, -19], [-18, 58, -19], [19, 59, 60], [-19, -59, 60], [-19, 59, -60], [20, 59, 60], [-20, -59, 60], [20, -59, -60], [-20, 59, -60], [21, 58, 20], [-21, -58, 20], [21, -58, -20], [-21, 58, -20], [22, 57, 21], [-22, -57, 21], [22, -57, -21], [-22, 57, -21], [23, 56, 22], [23, -56, -22], [-23, 56, -22], [24, 55, 23], [-24, -55, 23], [24, -55, -23], [-24, 55, -23], [-25, -54, 24], [25, -54, -24], [-25, 54, -24], [26, 53, 25], [-26, -53, 25], [26, -53, -25], [-26, 53, -25], [27, 52, 26], [-27, -52, 26], [27, -52, -26], [-27, 52, -26], [28, 51, 27], [-28, -51, 27], [-28, 51, -27], [29, 50, 28], [-29, -50, 28], [29, -50, -28], [-29, 50, -28], [30, 49, 29], [-30, -49, 29], [30, -49,-29], [-30, 49, -29], [31, 48, 30], [-31, -48, 30], [31, -48, -30], [-31, 48, -30], [32, 47, 31], [-32, -47, 31], [32, -47, -31], [-32, 47, -31], [33, 46, 32], [33, -46, -32], [-33, 46, -32], [34, 45, 33], [-34, -45, 33], [34, -45, -33], [-34, 45, -33], [35, 44, 34], [-35, -44, 34], [35, -44, -34], [-35, 44, -34],[36, 43, 35], [-36, -43, 35], [-36, 43, -35], [37, 42, 36], [-37, -42, 36], [37, -42, -36], [-37, 42, -36], [38, 41, 37], [-38, -41, 37], [38, -41, -37], [39, 40, -38], [-39, -40, -38], [39, -40, 38], [-39, 40, 38]]
I have figured out how to import the file but am having trouble converting it from a String -> [[Int]].
How would I go about do so?
haskell types
What you are asking and how far you have gotten is unclear. If you have "imported" this file then you shouldn't have a string. 1. What does the file look like exactly? 2. How are you importing it? I suspect you have a file with exactly the above quoted data and you haven't imported it but instead read it a lareadFile
or similar - hence my question.
– Thomas M. DuBuisson
Nov 14 '18 at 3:05
then I may not have even imported(read) the file correctly. the file contains exactly whats written.
– Famous Jameis
Nov 14 '18 at 13:21
1
idownvotedbecau.se/noattempt
– Michael Litchard
Nov 14 '18 at 15:39
Consider saving your data in another format like json.
– cheersmate
Nov 14 '18 at 16:36
to give some background, this problem i am having is for a stupid class where I need to solve the SAT (google it), I've already written a solution but am having a problem finding documentation on getting an ENTIRE (not line by line)file, into a string and converting it into the intended type. I don't care about JSON because in a week i won't care about this assignment, etc etc.
– Famous Jameis
Nov 14 '18 at 18:45
|
show 1 more comment
I have a file that contains a list of lists,
namely [[39, 40, 1], [-39, -40, 1], [-39, 40, -1], [1, 41, 2], [-1, -41, 2], [-1, 41, -2], [2, 42, 3], [-2, -42, 3], [-2, 42, -3], [3, 43, 4], [-3, -43, 4], [-3, 43, -4], [4, 44, 5], [-4, -44, 5], [-4, 44, -5], [5, 45, 6], [-5, -45, 6], [-5, 45, -6], [6, 46, 7], [-6, -46, 7], [6, -46, -7], [7, 47, 8], [-7, -47, 8], [7, -47, -8], [-7, 47, -8], [8, 48, 9], [8, -48, -9], [-8, 48, -9], [9, 49, 10], [-9, -49, 10], [9, -49, -10], [-9, 49, -10], [10, 50, 11], [10, -50, -11], [-10, 50, -11], [11, 51, 12], [-11, -51, 12], [11, -51, -12], [-11, 51, -12], [-12, -52, 13], [12, -52, -13], [-12, 52, -13], [-13, -53, 14], [13, -53, -14], [-13, 53, -14], [14, 54, 15], [-14, -54, 15], [14, -54, -15], [-14, 54, -15], [-15, -55, 16], [15, -55, -16], [-15, 55, -16], [16, 56, 17], [-16, -56, 17], [16, -56, -17], [-16, 56, -17], [17, 57, 18], [-17, -57, 18], [-17, 57, -18], [18, 58, 19], [-18, -58, 19], [18, -58, -19], [-18, 58, -19], [19, 59, 60], [-19, -59, 60], [-19, 59, -60], [20, 59, 60], [-20, -59, 60], [20, -59, -60], [-20, 59, -60], [21, 58, 20], [-21, -58, 20], [21, -58, -20], [-21, 58, -20], [22, 57, 21], [-22, -57, 21], [22, -57, -21], [-22, 57, -21], [23, 56, 22], [23, -56, -22], [-23, 56, -22], [24, 55, 23], [-24, -55, 23], [24, -55, -23], [-24, 55, -23], [-25, -54, 24], [25, -54, -24], [-25, 54, -24], [26, 53, 25], [-26, -53, 25], [26, -53, -25], [-26, 53, -25], [27, 52, 26], [-27, -52, 26], [27, -52, -26], [-27, 52, -26], [28, 51, 27], [-28, -51, 27], [-28, 51, -27], [29, 50, 28], [-29, -50, 28], [29, -50, -28], [-29, 50, -28], [30, 49, 29], [-30, -49, 29], [30, -49,-29], [-30, 49, -29], [31, 48, 30], [-31, -48, 30], [31, -48, -30], [-31, 48, -30], [32, 47, 31], [-32, -47, 31], [32, -47, -31], [-32, 47, -31], [33, 46, 32], [33, -46, -32], [-33, 46, -32], [34, 45, 33], [-34, -45, 33], [34, -45, -33], [-34, 45, -33], [35, 44, 34], [-35, -44, 34], [35, -44, -34], [-35, 44, -34],[36, 43, 35], [-36, -43, 35], [-36, 43, -35], [37, 42, 36], [-37, -42, 36], [37, -42, -36], [-37, 42, -36], [38, 41, 37], [-38, -41, 37], [38, -41, -37], [39, 40, -38], [-39, -40, -38], [39, -40, 38], [-39, 40, 38]]
I have figured out how to import the file but am having trouble converting it from a String -> [[Int]].
How would I go about do so?
haskell types
I have a file that contains a list of lists,
namely [[39, 40, 1], [-39, -40, 1], [-39, 40, -1], [1, 41, 2], [-1, -41, 2], [-1, 41, -2], [2, 42, 3], [-2, -42, 3], [-2, 42, -3], [3, 43, 4], [-3, -43, 4], [-3, 43, -4], [4, 44, 5], [-4, -44, 5], [-4, 44, -5], [5, 45, 6], [-5, -45, 6], [-5, 45, -6], [6, 46, 7], [-6, -46, 7], [6, -46, -7], [7, 47, 8], [-7, -47, 8], [7, -47, -8], [-7, 47, -8], [8, 48, 9], [8, -48, -9], [-8, 48, -9], [9, 49, 10], [-9, -49, 10], [9, -49, -10], [-9, 49, -10], [10, 50, 11], [10, -50, -11], [-10, 50, -11], [11, 51, 12], [-11, -51, 12], [11, -51, -12], [-11, 51, -12], [-12, -52, 13], [12, -52, -13], [-12, 52, -13], [-13, -53, 14], [13, -53, -14], [-13, 53, -14], [14, 54, 15], [-14, -54, 15], [14, -54, -15], [-14, 54, -15], [-15, -55, 16], [15, -55, -16], [-15, 55, -16], [16, 56, 17], [-16, -56, 17], [16, -56, -17], [-16, 56, -17], [17, 57, 18], [-17, -57, 18], [-17, 57, -18], [18, 58, 19], [-18, -58, 19], [18, -58, -19], [-18, 58, -19], [19, 59, 60], [-19, -59, 60], [-19, 59, -60], [20, 59, 60], [-20, -59, 60], [20, -59, -60], [-20, 59, -60], [21, 58, 20], [-21, -58, 20], [21, -58, -20], [-21, 58, -20], [22, 57, 21], [-22, -57, 21], [22, -57, -21], [-22, 57, -21], [23, 56, 22], [23, -56, -22], [-23, 56, -22], [24, 55, 23], [-24, -55, 23], [24, -55, -23], [-24, 55, -23], [-25, -54, 24], [25, -54, -24], [-25, 54, -24], [26, 53, 25], [-26, -53, 25], [26, -53, -25], [-26, 53, -25], [27, 52, 26], [-27, -52, 26], [27, -52, -26], [-27, 52, -26], [28, 51, 27], [-28, -51, 27], [-28, 51, -27], [29, 50, 28], [-29, -50, 28], [29, -50, -28], [-29, 50, -28], [30, 49, 29], [-30, -49, 29], [30, -49,-29], [-30, 49, -29], [31, 48, 30], [-31, -48, 30], [31, -48, -30], [-31, 48, -30], [32, 47, 31], [-32, -47, 31], [32, -47, -31], [-32, 47, -31], [33, 46, 32], [33, -46, -32], [-33, 46, -32], [34, 45, 33], [-34, -45, 33], [34, -45, -33], [-34, 45, -33], [35, 44, 34], [-35, -44, 34], [35, -44, -34], [-35, 44, -34],[36, 43, 35], [-36, -43, 35], [-36, 43, -35], [37, 42, 36], [-37, -42, 36], [37, -42, -36], [-37, 42, -36], [38, 41, 37], [-38, -41, 37], [38, -41, -37], [39, 40, -38], [-39, -40, -38], [39, -40, 38], [-39, 40, 38]]
I have figured out how to import the file but am having trouble converting it from a String -> [[Int]].
How would I go about do so?
haskell types
haskell types
asked Nov 14 '18 at 2:28
Famous JameisFamous Jameis
12
12
What you are asking and how far you have gotten is unclear. If you have "imported" this file then you shouldn't have a string. 1. What does the file look like exactly? 2. How are you importing it? I suspect you have a file with exactly the above quoted data and you haven't imported it but instead read it a lareadFile
or similar - hence my question.
– Thomas M. DuBuisson
Nov 14 '18 at 3:05
then I may not have even imported(read) the file correctly. the file contains exactly whats written.
– Famous Jameis
Nov 14 '18 at 13:21
1
idownvotedbecau.se/noattempt
– Michael Litchard
Nov 14 '18 at 15:39
Consider saving your data in another format like json.
– cheersmate
Nov 14 '18 at 16:36
to give some background, this problem i am having is for a stupid class where I need to solve the SAT (google it), I've already written a solution but am having a problem finding documentation on getting an ENTIRE (not line by line)file, into a string and converting it into the intended type. I don't care about JSON because in a week i won't care about this assignment, etc etc.
– Famous Jameis
Nov 14 '18 at 18:45
|
show 1 more comment
What you are asking and how far you have gotten is unclear. If you have "imported" this file then you shouldn't have a string. 1. What does the file look like exactly? 2. How are you importing it? I suspect you have a file with exactly the above quoted data and you haven't imported it but instead read it a lareadFile
or similar - hence my question.
– Thomas M. DuBuisson
Nov 14 '18 at 3:05
then I may not have even imported(read) the file correctly. the file contains exactly whats written.
– Famous Jameis
Nov 14 '18 at 13:21
1
idownvotedbecau.se/noattempt
– Michael Litchard
Nov 14 '18 at 15:39
Consider saving your data in another format like json.
– cheersmate
Nov 14 '18 at 16:36
to give some background, this problem i am having is for a stupid class where I need to solve the SAT (google it), I've already written a solution but am having a problem finding documentation on getting an ENTIRE (not line by line)file, into a string and converting it into the intended type. I don't care about JSON because in a week i won't care about this assignment, etc etc.
– Famous Jameis
Nov 14 '18 at 18:45
What you are asking and how far you have gotten is unclear. If you have "imported" this file then you shouldn't have a string. 1. What does the file look like exactly? 2. How are you importing it? I suspect you have a file with exactly the above quoted data and you haven't imported it but instead read it a la
readFile
or similar - hence my question.– Thomas M. DuBuisson
Nov 14 '18 at 3:05
What you are asking and how far you have gotten is unclear. If you have "imported" this file then you shouldn't have a string. 1. What does the file look like exactly? 2. How are you importing it? I suspect you have a file with exactly the above quoted data and you haven't imported it but instead read it a la
readFile
or similar - hence my question.– Thomas M. DuBuisson
Nov 14 '18 at 3:05
then I may not have even imported(read) the file correctly. the file contains exactly whats written.
– Famous Jameis
Nov 14 '18 at 13:21
then I may not have even imported(read) the file correctly. the file contains exactly whats written.
– Famous Jameis
Nov 14 '18 at 13:21
1
1
idownvotedbecau.se/noattempt
– Michael Litchard
Nov 14 '18 at 15:39
idownvotedbecau.se/noattempt
– Michael Litchard
Nov 14 '18 at 15:39
Consider saving your data in another format like json.
– cheersmate
Nov 14 '18 at 16:36
Consider saving your data in another format like json.
– cheersmate
Nov 14 '18 at 16:36
to give some background, this problem i am having is for a stupid class where I need to solve the SAT (google it), I've already written a solution but am having a problem finding documentation on getting an ENTIRE (not line by line)file, into a string and converting it into the intended type. I don't care about JSON because in a week i won't care about this assignment, etc etc.
– Famous Jameis
Nov 14 '18 at 18:45
to give some background, this problem i am having is for a stupid class where I need to solve the SAT (google it), I've already written a solution but am having a problem finding documentation on getting an ENTIRE (not line by line)file, into a string and converting it into the intended type. I don't care about JSON because in a week i won't care about this assignment, etc etc.
– Famous Jameis
Nov 14 '18 at 18:45
|
show 1 more comment
1 Answer
1
active
oldest
votes
You can use the read or readMaybe function.
For example,
b :: [[Int]]
b = read "[[3, 4], [4, -5]]"
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53292342%2fhaskell-convert-string-representation-of-integer-list-of-lists-to-integer-list%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use the read or readMaybe function.
For example,
b :: [[Int]]
b = read "[[3, 4], [4, -5]]"
add a comment |
You can use the read or readMaybe function.
For example,
b :: [[Int]]
b = read "[[3, 4], [4, -5]]"
add a comment |
You can use the read or readMaybe function.
For example,
b :: [[Int]]
b = read "[[3, 4], [4, -5]]"
You can use the read or readMaybe function.
For example,
b :: [[Int]]
b = read "[[3, 4], [4, -5]]"
answered Nov 14 '18 at 3:18
merlynmerlyn
1,72011222
1,72011222
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53292342%2fhaskell-convert-string-representation-of-integer-list-of-lists-to-integer-list%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What you are asking and how far you have gotten is unclear. If you have "imported" this file then you shouldn't have a string. 1. What does the file look like exactly? 2. How are you importing it? I suspect you have a file with exactly the above quoted data and you haven't imported it but instead read it a la
readFile
or similar - hence my question.– Thomas M. DuBuisson
Nov 14 '18 at 3:05
then I may not have even imported(read) the file correctly. the file contains exactly whats written.
– Famous Jameis
Nov 14 '18 at 13:21
1
idownvotedbecau.se/noattempt
– Michael Litchard
Nov 14 '18 at 15:39
Consider saving your data in another format like json.
– cheersmate
Nov 14 '18 at 16:36
to give some background, this problem i am having is for a stupid class where I need to solve the SAT (google it), I've already written a solution but am having a problem finding documentation on getting an ENTIRE (not line by line)file, into a string and converting it into the intended type. I don't care about JSON because in a week i won't care about this assignment, etc etc.
– Famous Jameis
Nov 14 '18 at 18:45