Hacktoberfest 2026 : les issues que les mainteneurs ont marquées pour octobre, ouvertes et accessibles aux débutants. Parcourir les issues Hacktoberfest

Type inference limitation with records and SRTP

Ouverte
#685 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

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

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

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

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de fsprojects/FSharpPlus

Toutes les issues de fsprojects/FSharpPlus

Issues similaires

Plus d'issues Compilers

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.