Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Type inference limitation with records and SRTP

オープン
#685 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
12/100
issue の種類
バグ
明瞭さ
説明が足りない
活発さ
活発
技術スタック
fsharp
領域
compilers

調査の方向性

The snippet is in the issue body and uses the applicative computation expression with List.choose in FSharpPlus. Reproduce it with four and! bindings and the record construction, then compare against the documented workaround that annotates List.choose with the record type. The reporter says the fix belongs in the F# compiler, not this library, and no scope for a change in this repo is stated. Done would mean a minimal reproduction and a clear statement of where the inference fails.

索引モデルが issue の本文から書いたものです。

説明

F# Compiler Bug
Description

Type inference for records is a bit special in F# and it doesn't play well with SRTPs
I've seen many cases, but here's a cool one:

#r "nuget: FSharpPlus"

open FSharpPlus
type Station = { Icao: string; Lat: float; Lon: float; Raw: string }

let private parseStations (json: string) =
    ["1"; "2"]
    |> List.choose<_, Station> (fun e ->
        let str (n: string) : string option = tryParse<int> n |> Option.map string
        let num (n: string) : float option  = tryParse<int> n |> Option.map float

        applicative {
            let! icao = str "icaoId"
            and! raw  = str "rawOb"
            and! lat  = num "lat"
            and! lon  = num "lon"
            return { Station.Icao = icao; Station.Lat = lat; Station.Lon = lon; Station.Raw = raw }
        })

Note that this fails when it has more that 3 parameters in the final binding (I have 4 in the code)

Known Workarounds

Add type parameter annotation in the choose about the record type:

#r "nuget: FSharpPlus"

open FSharpPlus
type Station = { Icao: string; Lat: float; Lon: float; Raw: string }

let private parseStations (json: string) =
    ["1"; "2"]
    |> List.choose<_, Station> (fun e ->
        let str (n: string) : string option = tryParse<int> n |> Option.map string
        let num (n: string) : float option  = tryParse<int> n |> Option.map float

        applicative {
            let! icao = str "icaoId"
            and! raw  = str "rawOb"
            and! lat  = num "lat"
            and! lon  = num "lon"
            return { Station.Icao = icao; Station.Lat = lat; Station.Lon = lon; Station.Raw = raw }
        })
Expected behavior

Workaround not needed.
This is an F# type inference limitation and should be solved in the F# compiler.

Actual behavior

No response

Configuration

No response

Reproduction Steps

No response

Are you willing to help with a pull-request?

No

主要言語
F#
スター
942
フォーク
105
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

fsprojects/FSharpPlus のほかの issue

fsprojects/FSharpPlus の issue をすべて見る

似ている issue

Compilers の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。