Q:

Converting seq to string[] in F#

The example from this post has an example
open System.IO

let lines = 
  File.ReadAllLines("tclscript.do")
  |> Seq.map (fun line ->
      let newLine = line.Replace("{", "{{").Replace("}", "}}")
      newLine )

File.WriteAllLines("tclscript.txt", lines)

that gives an error when compilation.
error FS0001: This expression was expected to have type
    string []    
but here has type
    seq<string> 

How to convert seq to string[] to remove this error message?

A:

Building on Jaime's answer, since ReadAllLines() returns an array, just use Array.map instead of Seq.map
open System.IO

let lines = 
  File.ReadAllLines("tclscript.do")
  |> Array.map (fun line ->
      let newLine = line.Replace("{", "{{").Replace("}", "}}")
      newLine )

File.WriteAllLines("tclscript.txt", lines)

A:

You can use
File.WriteAllLines("tclscript.txt", Seq.toArray lines)

or alternatively just attach
|> Seq.toArray

after the Seq.map call.
(Also note that in .NET 4, there is an overload of WriteAllLines that does take a Seq)

