haskell - How can I concatenate user input in a list -


i codes user , insert in list, problem when user don't wanna insert more codes. don't saved list numbers because i'm using recursion call method again, when should return list don't have it.

insertcode :: [integer] insertcode =     putstrln "code:"     code <- getline     putstrln "another? (y/n)"     if(resp == "y" || resp == "y") (read code::string->integer):insertcode else --i don't know 

i'm sorry stupids questions, imagine obvious have problem functional programming

first of all, type signature wrong. insertcode uses io monad, type must io [integer]. missing conversion of code string integer (i use readln accomplish that; trying convert code function, not integer) , missing getline y/n response user.

once fixed, might write following:

insertcode :: io [integer] insertcode =     putstrln "code:"     code <- readln     putstrln "another? (y/n)"     response <- getline     result <- if (response == "y" || response == "y")               insertcode               else return []     return (code : result) 

this little verbose, tries explicit how monad used. whether user enters y or n, code must appended list extracted monad: either list extracted recursive use of insertcode, or explicit empty list.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -