File input/output: Difference between revisions

Content added Content deleted
No edit summary
(→‎{{header|F Sharp|F#}}: comply to task description by using an intermediate variable)
Line 788: Line 788:


=={{header|F Sharp|F#}}==
=={{header|F Sharp|F#}}==
Using an intermediate variable for the input file content is not ideomatic in functional programming. Nevertheless...


<lang fsharp>open System.IO
<lang fsharp>open System.IO


let copyFile fromTextFileName toTextFileName =
let read = File.ReadAllText
let inputContent = File.ReadAllText fromTextFileName
let write file text = File.WriteAllText(file, text)
inputContent |> fun text -> File.WriteAllText(toTextFileName, text)


[<EntryPoint>]
"input.txt" |> read |> write "output.txt"
let main argv =
copyFile "input.txt" "output.txt"
0
</lang>
</lang>