Type inference limitation with records and SRTP
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
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
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de fsprojects/FSharpPlus
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 45/100
fsprojects/FSharpPlus#684 ·
-
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 35/100
fsprojects/FSharpPlus#683 · 1 comentário · 2 reações ·
-
bug
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 35/100
fsprojects/FSharpPlus#678 ·
-
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 35/100
fsprojects/FSharpPlus#644 ·
-
breaking change F#+ v2.0
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 30/100
fsprojects/FSharpPlus#643 ·
Todas as issues de fsprojects/FSharpPlus
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
FuRongJun-1999/dsh-memory#402 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
-
bug frontend
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
PennyLaneAI/catalyst#3337 ·
Mantenedores costumam responder em até 1 dia
-
Real literal with a 'd' exponent and a kind suffix (1.0d0_4) is accepted; the suffix is ignoredAbertaerror not reported low priority semantics
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
Mantenedores costumam responder em até 1 dia
-
draft
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 66/100
Mantenedores costumam responder em até 1 dia