필드가 겹치는 레코드 유형 통합

Dec 31 2020

다음 코드가 있습니다.

workWithImportantField :: forall fields. { importantField :: Int | fields } -> Input
workWithImportantField = ...

workWithImportantField $ 
maybe { importantField: 1 } identity (Just { importantField: 1, fieldIDontCareAbout: "whatever" })

첫 번째 레코드에 fieldIDontCareAbout. 그러나으로 통합 forall fields. { importantField :: Int | fields }되어 workWithImportantField. 어떻게할까요?

여러 위치 (첫 번째 레코드, 두 번째 레코드, 전체 표현식)에 유형 주석을 추가하려고 시도했지만 성공하지 못했습니다. 나는 항상 대체 할 수 identity와 함께 unsafeCoerce,하지만 난 형태 보증 된 솔루션을하고 싶습니다. 으로 대체 identity하여 필요한 필드를 수동으로 선택할 수도 \{ importantField } -> { importantField }있지만 좋지 않습니다.

답변

bklaric Dec 31 2020 at 05:10

교체 identitypick에서 발견 Record.Extra "버린다" fieldIDontCareAbout유형이 통합되도록 두 번째 레코드에서.