Type inference limitation with records and SRTP
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Accessibilité débutants
- 12/100
- Type d'issue
- Bug
- Clarté
- À clarifier
- Activité
- Active
- Stack technique
- fsharp
- Domaine
- compilers
Piste de recherche
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.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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
- Langage dominant
- F#
- Étoiles
- 942
- Forks
- 105
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Préparer son environnement
Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de fsprojects/FSharpPlus
-
Difficulté 4/5 3-5 jours Accessibilité débutants 45/100
fsprojects/FSharpPlus#684 ·
-
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 35/100
fsprojects/FSharpPlus#683 · 1 commentaire · 2 réactions ·
-
bug
Difficulté 3/5 1-2 jours Accessibilité débutants 35/100
fsprojects/FSharpPlus#678 ·
-
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 35/100
fsprojects/FSharpPlus#644 ·
-
breaking change F#+ v2.0
Difficulté 4/5 3-5 jours Accessibilité débutants 30/100
fsprojects/FSharpPlus#643 ·
Toutes les issues de fsprojects/FSharpPlus
Issues similaires
-
area: compat area: parsing bug
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
reubeno/brush#1526 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
Les mainteneurs répondent en général sous 1 jour