I am making the pilgrimage from Java to Haskell. Broadly speaking, I get the main concepts behind Haskell. Reading all the tutorials and books 'makes sense' but I am getting stuck writing my own code from scratch.
I want to create 1000 files on the file system with names
"myfile_1.txt" ... "myfile_1000.txt"
and each containing some dummy text.
so far I have worked out the whole IO thing, and realise I need to build a list of Strings 1000 elements long. So I have:
buildNamesList :: [] -> []
buildNamesList ???
Once I have the List I can call the writefile method on each element. What I can't figure out is how to add a number to the end of a String to get each fileName because I can't have an int i = 0, i ++ construct in Haskell.
I am a bit out of my depth here, would appreciate some guidance, thanks
[] -> []? That doesn't make any sense,[]is not a type but a type constructor. You probably mean[a]->[a], but that's not really right either. — Generally, it seems to me you have not understood the main concepts behind Haskell. You don't want to "build" a list, you just define it. You don't "call the writefile method on each element", but traverse a list (e.g. withmapM_). You also don't really "add something to the end of a string", you rather define a new postfixed string – though, actually, we do call this adding to the end.