Convert a list of characters (or array) to a string

前端 未结 4 843
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-07 03:57

how does one convert from a list of characters to a string?

To put it another way, how do I reverse List.ofSeq \"abcd\"?

UPDATE: new System.St

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-07 04:13

    I asked a similar question once before. It seems object constructors aren't composable so you can't pass them as a function.

    List.ofSeq "abcd" |> List.toArray |> (fun s -> System.String s) |> printfn "%A"
    List.ofSeq "abcd" |> List.toArray |> (fun s -> new System.String(s)) |> printfn "%A"
    

    Update Constructors are first-class functions as of F# 4.0

    List.ofSeq "abcd" |> List.toArray |> System.String |> printfn "%A"
    

提交回复
热议问题