I have a config.cfg file where a the variable file_list is a list of relative path to files
file_list = file1 dir1/file2 ../dir2/file3
How do I read this variable in to get a file_list::[FilePath]?
Tried to follow the Development.Shake.Config API Doc without success. I need something to achieve that
file_list <- getConfig "file_list"
let fl = ??? file_list
need fl
ps. I'am an Haskell beginner
The type of
file_listisMaybe String, and the type offlneeds to be[FilePath], so the question becomes how to write a function to transform between the two. One option is:The
fromMaybefunction replacesNothingwith""- so you now have aString. Thewordsfunction splits a string on the spaces, to produce[String]. In HaskellFilePathis a synonym forStringso it all works out.If instead you want to error out if the key is missing, you can do:
Now you are asserting and unwrapping the
Maybeinfile_list, so if it isNothingyou get a runtime crash, and if it isJustyou get it without theJustwrapper, so can simply usewords.