Type inference limitation with records and SRTP
まだ誰も着手していません。
評価
- 難易度
- 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 の本文から書いたものです。
説明
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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
fsprojects/FSharpPlus のほかの issue
-
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
fsprojects/FSharpPlus#684 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
fsprojects/FSharpPlus#683 · コメント 1 件 · リアクション 2 件 ·
-
bug
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
fsprojects/FSharpPlus#678 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
fsprojects/FSharpPlus#644 ·
-
breaking change F#+ v2.0
難易度 4/5 3〜5日 初心者へのやさしさ 30/100
fsprojects/FSharpPlus#643 ·
fsprojects/FSharpPlus の issue をすべて見る
似ている issue
-
bot-triaged module: activation checkpointing module: inductor oncall: pt2 triaged
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
calcit-lang/calcit#2075 ·
メンテナーはふだん 1 日以内に返信
-
area:observer enhancement found-by:cold-read good first issue
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
InauguralSystems/EigenScript#1781 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
webgpu-tools/wesl-rs#331 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
limitlessprojects/Go-Hybrid#50 ·
メンテナーはふだん 1 日以内に返信