简体   繁体   中英

Haskell convert string to integer list

I have the following string [1..5] and I want to convert it to the Integer list [1,2,3,4,5]. I tried doing this using read but that does not work. Is there any simple trick to convert such a list to an Integer list or will it require a parser?

I guess you will need an interpreter to do so. You might want to do something along the line of:

$ cabal install hint
...
$ ghci
> import Language.Haskell.Interpreter
> runInterpreter $ setImports ["Prelude"] >> eval "[1..5]"

Also see this answer: https://stackoverflow.com/a/5584638/55070

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM