I'm trying to create a List reading a text file, for example I have a text file like this "1 5 12 9 2 6" and I want to create a list like this [1,5,12,9,2,6] using SML
Create a list reading a file with SML
433 Views Asked by Gabrielenones At
1
There are 1 best solutions below
Related Questions in SML
- Creating an instance of a Binary Tree (Programming Standard ML by Robert Harper)
- Obtain a function as tree in SML
- TextIO.openIn:"No such file or directory" in Poly/ML
- How to implement Label/TextVIew with giraffe library in SML
- Compiling Giraffe library Hello World on Ubuntu
- How to match function type in signature in SML
- Error "no *.cm, *.mlb, or millet.toml files found in this directory" in VS code using SML
- I'm new to SML/NJ and there's some questions bothering me. I don't know how to use Math or String in the basis lib
- SML Looping through 2 Random variables and ordering them?
- How do I fix my standard ml code when I have an unbound value 'a'?
- How to install and run SML/ NJ in VScode
- UTF-8, Unicode in SML/NJ
- What is the difference between ('a,'b) and ('a*'b)?
- sml standard pop function vs user defiend. And return values
- Error: unbound type constructor: TypeInteger
Related Questions in POLYML
- Obtain a function as tree in SML
- TextIO.openIn:"No such file or directory" in Poly/ML
- How to implement Label/TextVIew with giraffe library in SML
- Compiling Giraffe library Hello World on Ubuntu
- polyml CommandLine.arguments() returns nonsense
- RunCall structure of Poly/ML
- Datatype declaration by datatype in Standard ML
- Quotation mechanism for PolyML top level
- PolyML colored output to terminal in Linux
- What causes the SML error: Exception- InternalError: asGenReg raised while compiling
- Why am I getting this error for a function that simply adds a value to every integer in a list?
- Error compiling with polyc on Debian 10 Buster
- StandardML factorial evaluation enters infinite loop in Poly/ML REPL
- I don't know how to open and run sml files with PolyML
- Counting elements list without duplicates in Poly/ML programming
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
You can divide this task into several sub-problems:
Reading a file into a string can be done with
See the
TextIOlibrary.Converting a string into a list of strings separated by whitespace can be done with
See the
String.tokensfunction.Converting a list of strings into a list of integers can be done with
Since any one string-to-integer conversion with
Int.fromStringmay fail and produce aNONE,List.map Int.fromStringwill produce an "int option list" rather than an "int list". This list of "int option" may be converted to an optional "int list", i.e., remove theSOMEof all the "int option", but if there's a singleNONE, the entire result is discarded and becomesNONE. This gives the final type "int list option" (eitherNONEorSOME [1,2,...]).See the
Option.mapfunction which was useful for this kind of recursion.Combining these,
This approach does yield some potentially unwanted behavior:
readIntegersthrow anIoexception~5inside the file will be interpreted as negative five-5will produce a failure (NONE)123awill produce the number 123 (Int.toStringis a bit too forgiving)You may want to address those.