I need to execute the cp_r function from the Shelly library to copy a to b.
However,
import Shelly
main = do cp_r "a" "b"
yields
Couldn't match expected type `Shelly.FilePath'
            with actual type `[Char]'
In the first argument of `cp_r', namely `"a"'
In the expression: cp_r "a" "b"
In an equation for `it': it = cp_r "a" "b"
for both the first and the second argument to cp_r.
How can I use String (FilePath is defined as String on any platform I know of) as argument to cp_r?
Note: This question intentionally does not show any research effort as it was answered Q&A-Style.
 
                        
For a detailed and official description, see the convert between Text and FilePath section on Hackage.
Let's first see how to do it with
Text:From here on, we can just use
Text.packto apply this method to stringsNote that in case you also need to use the
FilePathfromPreludein a module, you need to useto avoid conflicts (alternatively, you could use
Prelude.FilePathandShelly.FilePath).