전체 이름을 매번 쓰기 싫다면 F#에서 open을 쓸 수 있습니다:
open System
let greeting = String.Format("Hello {0}", "world")
이건 일반 컴파일 애플리케이션과 F# interactive 모두에서 됩니다(open 선언을 먼저 입력하세요). 여기서 중요한 건 String을 대문자 S로 쓰는 것입니다. C#의 string은 일반적인 타입 이름이 아니라 System.String을 가리키는 키워드이기 때문입니다.
다른 선택지로 sprintf도 살펴보세요. 이건 String.Format에 대응하는 F# 전용 함수로, 타입 검사를 해 준다는 등의 장점이 있습니다:
let greeting = sprintf "Hello %s! Number is %d" "world" 56
컴파일러가 인수(string과 int)가 서식 표시에 맞는지 검사합니다(%s는 문자열, %d는 정수입니다). 부분 함수 적용을 할 때도 이 함수가 더 자연스럽습니다:
let values = [ 3 .. 12 ]
let descriptions = values |> List.map (sprintf "number %d")
그러면 "number 3", "number 4" 등이 담긴 문자열 목록이 나옵니다... String.Format으로 똑같이 하려면 람다 함수를 직접 작성해야 합니다.
영어에서 번역·원문 보기To skip spelling out the fully qualified name, F# lets you use open:
open System
let greeting = String.Format("Hello {0}", "world")
That works in an ordinary compiled application as well as F# interactive (submit the open declaration beforehand). What's important here is spelling String with a capital S. The reson is that C#'s string isn't an ordinary name for a type - it's a keyword referring to System.String.
Another option worth examining is sprintf. This F# alternative to String.Format offers useful advantages - one being that it is checked for correct types:
let greeting = sprintf "Hello %s! Number is %d" "world" 56
The compiler verifies that the arguments (string and int) agree with their format markers (%s means string, while %d means integers). Partial function application is another situation in which this function fits more naturally:
let values = [ 3 .. 12 ]
let descriptions = values |> List.map (sprintf "number %d")
The result is a list of strings holding "number 3", "number 4" and so on... Achieving the equivalent with String.Format would require writing out a lambda function.