Type inference limitation with records and SRTP
还没有人认领这个 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 内容生成。
描述
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,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
fsprojects/FSharpPlus 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 45/100
fsprojects/FSharpPlus#684 ·
-
难度 5/5 一周以上 新手友好度 35/100
fsprojects/FSharpPlus#683 · 1 条评论 · 2 个 reaction ·
-
bug
难度 3/5 1-2 天 新手友好度 35/100
fsprojects/FSharpPlus#678 ·
-
难度 5/5 一周以上 新手友好度 35/100
fsprojects/FSharpPlus#644 ·
-
breaking change F#+ v2.0
难度 4/5 3-5 天 新手友好度 30/100
fsprojects/FSharpPlus#643 ·
查看 fsprojects/FSharpPlus 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 70/100
维护者通常 1 天内回复
-
A `--symbolic` entry binding `𝑛3` and `!n3` passes the load check, since `once` compares spellings, and fails mid-run with a `user error`可能已有人在做 @sherenkov 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 66/100
objectionary/phino#1929 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
FuRongJun-1999/dsh-memory#402 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100