F# 4.6의 새로운 기능
F# 4.6은 F# 언어에 여러 개선 사항을 추가합니다.
시작하기
F# 4.6은 모든 .NET Core 배포 및 Visual Studio 도구에서 사용할 수 있습니다. F# 을 사용하여 자세히 알아보세요.
익명 레코드
익명 레코드 는 F# 4.6에 도입된 새로운 종류의 F# 형식입니다. 사용하기 전에 선언할 필요가 없는 명명된 값의 간단한 집계입니다. 구조체 또는 참조 형식으로 선언할 수 있습니다. 기본적으로 참조 형식입니다.
open System
let getCircleStats radius =
let d = radius * 2.0
let a = Math.PI * (radius ** 2.0)
let c = 2.0 * Math.PI * radius
{| Diameter = d; Area = a; Circumference = c |}
let r = 2.0
let stats = getCircleStats r
printfn "Circle with radius: %f has diameter %f, area %f, and circumference %f"
r stats.Diameter stats.Area stats.Circumference
값 형식을 그룹화하고 성능에 민감한 시나리오에서 작동하는 경우에 대한 구조체로 선언할 수도 있습니다.
open System
let getCircleStats radius =
let d = radius * 2.0
let a = Math.PI * (radius ** 2.0)
let c = 2.0 * Math.PI * radius
struct {| Diameter = d; Area = a; Circumference = c |}
let r = 2.0
let stats = getCircleStats r
printfn "Circle with radius: %f has diameter %f, area %f, and circumference %f"
r stats.Diameter stats.Area stats.Circumference
매우 강력하며 다양한 시나리오에서 사용할 수 있습니다. 익명 레코드에 대해 자세히 알아보세요.
ValueOption 함수
이제 F# 4.5에 추가된 ValueOption 형식에 옵션 형식이 있는 "모듈 바인딩 함수 패리티"가 있습니다. 일반적으로 사용되는 몇 가지 예제는 다음과 같습니다.
// Multiply a value option by 2 if it has value
let xOpt = ValueSome 99
let result = xOpt |> ValueOption.map (fun v -> v * 2)
// Reverse a string if it exists
let strOpt = ValueSome "Mirror image"
let reverse (str: string) =
match str with
| null
| "" -> ValueNone
| s ->
str.ToCharArray()
|> Array.rev
|> string
|> ValueSome
let reversedString = strOpt |> ValueOption.bind reverse
이렇게 하면 값 형식이 있으면 성능이 향상되는 시나리오에서 Option과 마찬가지로 ValueOption을 사용할 수 있습니다.
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기