Avoiding namespace pollution in Haskell

前端 未结 5 1710
鱼传尺愫
鱼传尺愫 2020-12-04 10:46

I\'m using lots of different records in a program, with some of them using the same field names, e.g.

data Customer = Customer { ..., foo :: Int, ... }
data          


        
5条回答
  •  情书的邮戳
    2020-12-04 11:12

    See also the Has package: http://chrisdone.com/posts/duck-typing-in-haskell

    And if you really need extensible records now, you can always use HList. But I wouldn't recommend this until you're really familiar and comfortable with medium-advanced Haskell, and even then I'd triple check you need it.

    Haskelldb has a slightly more lightweight version: http://hackage.haskell.org/packages/archive/haskelldb/2.1.0/doc/html/Database-HaskellDB-HDBRec.html

    And then there's another version of extensible records as part of the grapefruit frp library: http://hackage.haskell.org/package/grapefruit-records

    Again, for your purposes, I'd bite the bullet and just rename the fields. But these references are to show that when you really need the full power of extensible records, there are ways to do it, even if none are as pleasant as a well-designed language extension would be.

提交回复
热议问题