Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Type inference limitation with records and SRTP

未关闭
#685 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
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. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

fsprojects/FSharpPlus 的其他 Issue

查看 fsprojects/FSharpPlus 的全部 Issue

相似的 Issue

更多 Compilers Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。