1

I have a string array lines, for example

lines = [| "hello"; "world" |]

I'd like to make a string line that concatenates the elements in lines with "code=" string prepended. For example, I need to get the string code="helloworld" from the lines array.

I could get the concatenated string with this code

let concatenatedLine = lines |> String.concat "" 

And I tested this code to prepend "code=" string as follows, but I got error FS0001: The type 'string' is not compatible with the type 'seq<string>' error.

let concatenatedLine = "code=" + lines |> String.concat "" 

What's wrong with this?

2 Answers 2

5

+ binds stronger than |>, so you need to add some parentheses:

let concatenatedLine = "code=" + (lines |> String.concat "")

Otherwise the compiler parses the expression like:

let concatenatedLine = (("code=" + lines) |> (String.concat ""))
                         ^^^^^^^^^^^^^^^
                         error FS0001 
Sign up to request clarification or add additional context in comments.

Comments

2

I think you want to try the following ( forward piping operator has lower precedence)

let concatenatedLine = "code=" + (lines |> String.concat "" )

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.