Name conflicts in Haskell records

前端 未结 3 1515
生来不讨喜
生来不讨喜 2020-12-08 04:41

Haskell doesn\'t have dot notation for record members. For each record member a compiler creates a function with the same name with a type RecType -> FieldType. This leads

3条回答
  •  一向
    一向 (楼主)
    2020-12-08 05:10

    The GHC developers developed a couple of extensions to help with this issue . Check out this ghc wiki page. Initially a single OverloadedRecordFields extension was planned, but instead two extensions were developed. The extensions are OverloadedLabels and DuplicateRecordFields. Also see that reddit discussion.

    The DuplicateRecordFields extensions makes this code legal in a single module:

    data Person  = MkPerson  { personId :: Int, name :: String }
    data Address = MkAddress { personId :: Int, address :: String }
    

    As of 2019, I'd say these two extensions didn't get the adoption I thought they would have (although they did get some adoption) and the status quo is probably still ongoing.

提交回复
热议问题