Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

Type inference limitation with records and SRTP

Aberta
#685 0 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
5/5
Tempo estimado
Mais de uma semana
Facilidade para iniciantes
12/100
Tipo de issue
Bug
Clareza
Precisa de esclarecimento
Status de atividade
Ativa
Stack de tecnologia
fsharp
Domínio
compilers

Direção de pesquisa

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.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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

Linguagem predominante
F#
Estrelas
942
Forks
105
Métricas de merge de PRs
Nenhum PR com merge em 30d

Preparar o ambiente

Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de fsprojects/FSharpPlus

Todas as issues de fsprojects/FSharpPlus

Issues semelhantes

Mais issues de Compilers

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.