女人吃什么补气血效果最好| uw是什么单位| 类风湿性关节炎的症状是什么| 布病吃什么药| o型血不能和什么血型的人生孩子| 双喜临门指什么生肖| 尿素酶阳性什么意思| 行长是什么级别| 5公里25分钟什么水平| 经期延长是什么原因引起的| 下腹隐隐作痛什么原因| gtp是什么| lpl是什么| 什么牌子的麦克风好用| 蓝色妖姬是什么意思| 什么中生什么| 开什么店最赚钱投资小| elaine是什么意思| 忙什么呢幽默的回答| 脂蛋白高说明什么问题| 发烧咳嗽吃什么药| 藏在什么里的爱| 灵隐寺求什么最灵| 经常感冒吃什么提高免疫力| 宝妈男是什么意思| 晚上减肥吃什么| 严重脱发是什么原因| 肱骨头小囊变什么意思| 汉菜不能和什么一起吃| 臭屁什么意思| ipa啤酒什么意思| 火车头是什么意思| siri是什么意思| 攸字五行属什么| 皮肤角质化用什么药膏| 普洱茶适合什么季节喝| 风雨雷电代表什么生肖| 天枢是什么意思| 气是什么| 右手发麻是什么原因| 五月23是什么星座| 路由器坏了有什么症状| 运营商是什么意思| 皮肤病挂什么科| 血脂高可以吃什么水果| 桃花什么时候开| 经常喝柠檬水有什么好处和坏处| 撒尿分叉是什么原因| 曲奇饼干为什么不成形| 凌晨四点是什么时辰| 大便很细是什么原因| ucs是什么意思| 做胃镜之前需要做什么准备| 诺贝尔奖是什么意思| 搁浅了是什么意思| 符咒是什么意思| 药店加盟需要什么条件| 什么马不能跑| 男人壮阳吃什么最快| plus什么意思| 农历今天属什么| 抗美援朝是什么时候| 乐高可以拼什么| 优字五行属什么| 象牙塔比喻什么| 沙门氏菌用什么药| 胎菊泡水喝有什么功效| 柔软的什么| 单身为什么中指戴戒指| 嘴无味是什么病的征兆| 突然勃不起来是什么原因造成的| 吃驼奶粉有什么好处| 肾虚吃什么中药| 勾股定理是什么意思| 泌尿科看什么病| 沈阳六院主要治什么病| 伏脉常见于什么病| 青玉是什么玉| 每天吃葡萄有什么好处和坏处| 每天坚持做俯卧撑有什么好处| 腰间盘突出有什么症状| 胃痛吃什么药最有效| 911是什么| 合是什么生肖| 喝苦荞茶对身体有什么好处| 大腿根部内侧瘙痒用什么药膏| 龟奴是什么| 劓刑是什么意思| 一元硬币是什么材质| 有什么游戏| 哪吒他妈叫什么名字| 金牛男和什么星座女最配| 免疫力和抵抗力有什么区别| 泌乳素什么时候查最准确| or是什么意思| 司马光和司马迁是什么关系| 舌头烧灼感是什么原因| 多吃蔬菜有什么好处| 土生土长是什么生肖| 71年什么时候退休| 下午17点是什么时辰| 法令纹上的痣代表什么| 嘚瑟是什么意思| 脚经常抽筋是什么原因| 外露什么意思| 什么牌子| 冰箱为什么老是结冰| 洛阳有什么山| 花椒什么时候传入中国| 卡码是什么意思| 决明子是什么| 为什么午睡起来会头疼| 46属什么| 梦见儿子小时候是什么意思| 黑脸代表什么| 外露什么意思| 胃疼吃什么药| 海鸥手表属于什么档次| 吃什么降三高最好| 憩室炎吃什么药| 腰痛去医院挂什么科| 曼陀罗是什么| 生肖狗和什么生肖相冲| 铁蛋白偏高是什么原因| betty是什么意思| 凶神宜忌是什么意思| 跑男什么时候播出| 男人出虚汗是什么原因引起的| 南瓜皮可以吃吗有什么作用| 满江红属于什么植物| 冰岛茶属于什么茶| 2028什么年| 心慌气短是什么原因| 脱敏处理是什么意思| 什么丰富| 体制内是什么意思| 用加一笔是什么字| 风水是什么意思| 在什么的前面用英语怎么说| px是什么意思| 窈窕淑女君子好逑是什么意思| 筋膜炎有什么症状| 牛肉补什么| 环比是什么意思| 肺部结节吃什么好| 耳廓有痣代表什么| 反式脂肪是什么| 血糖高的人应该吃什么食物最好| 冠脉硬化什么意思| 身上长肉疙瘩是什么原因| 维c不能和什么一起吃| 老鼠怕什么| 负担是什么意思| 是指什么| 追光是什么意思| 头痛吃什么药| 今天适合穿什么衣服| 臣附议是什么意思| 岁月蹉跎什么意思| 什么是早泄| 万宝龙属于什么档次| ABA是什么植物激素| NT是什么钱| 吗啡是什么| 大腿后侧肌肉叫什么| 山竹里面黄黄的是什么| 摩什么接什么| 小苏打是什么| 心有戚戚焉什么意思| 血栓是什么病| 输血前八项指什么| 断掌是什么意思| 梦见和死人说话是什么意思| 如意是什么意思| 女生纹身什么图案好看| 痔疮是什么意思| 甲木命是什么意思| 什么材质| 山水不相逢什么意思| 早上起来不晨勃是什么原因| 丙肝吃什么药效果好| 喝最烈的酒下一句是什么| 日月同辉是什么意思| 亚麻籽油是什么植物的籽榨出来的| 尾货是什么意思| 头皮脂溢性皮炎用什么药| 青定读什么| aupres是什么牌子化妆品| 女人吃鹿茸有什么好处| 耐克是什么牌子| 人中跳动是什么原因| 女人戴什么手串辟邪| eric是什么意思| 积是什么意思| 鲁是什么意思| 杨桃长什么样| o型血为什么叫熊猫血| 见利忘义是什么意思| 吃什么水果可以变白| 弥漫性脂肪肝什么意思| 师兄是什么意思| 林黛玉和贾宝玉是什么关系| 做喉镜能检查出什么病| 验光pd是什么意思| 牙龈发炎是什么原因引起的| 4月13日是什么星座| 2月7号是什么星座| 褪黑素有什么用| 脑供血不足什么原因| 什么是绿茶| 酸枣仁配什么治疗失眠| 豆油什么牌子的好| 新生儿眼屎多是什么原因| 什么叫暧昧| 吃皮蛋有什么好处和坏处| 观音菩萨成道日是什么意思| 角化型足癣用什么药| 女性解脲支原体阳性吃什么药| mra检查是什么意思| 糯米是什么米| 处女和什么座最配对| 左腿酸痛是什么原因| 明心见性是什么意思| 左下腹疼痛是什么原因| daks是什么品牌| 唐僧被封为什么佛| 深谙是什么意思| 身体水肿是什么原因引起的| 眼底出血是什么原因| 为什么辰不能见亥| 润什么意思| 全身发麻是什么原因引起的| 做可乐鸡翅用什么可乐| 供奉财神爷有什么讲究| 焦的部首是什么| 神经衰弱吃什么药好| 球虫病有什么症状| 原发性肝ca什么意思| 肾结石可以喝什么饮料| 亚急性甲状腺炎吃什么药| 巴字加一笔是什么字| 对数是什么| 肠胃炎什么症状| 敏五行属什么| 什么东西解腻| 资深是什么意思| 什么体质容易长肿瘤| 塑形是什么意思| 缺铁性贫血有什么症状| 血癌是什么原因造成的| 苹果是什么季节成熟的| 尿路感染什么症状| 女性阴部痒是什么原因| 红豆有什么功效| 忽视是什么意思| 小猫的尾巴有什么作用| 毛拉是什么意思| 吐槽是什么意思啊| 掉发严重是什么原因| ppi下降意味着什么| da是什么单位| 浸洗是什么意思| 请问今晚买什么生肖| 护照办理需要什么材料| 百度
Skip to content

Instantly share code, notes, and snippets.

@nikita-volkov

习近平将出席“一带一路”国际合作高峰论坛开幕式

Last active July 4, 2022 13:33
Show Gist options
  • Save nikita-volkov/6977841 to your computer and use it in GitHub Desktop.
Save nikita-volkov/6977841 to your computer and use it in GitHub Desktop.
Anonymous records. A solution to the problems of record-system.

#Anonymous records. A solution to the problems of record-system.

Please, beware that the proposal that follows has been implemented as a library.

The current record system is notorious for three major flaws:

  1. It does not solve the namespacing problem. I.e., you cannot have two records sharing field names in a single module. E.g., the following won't compile:

    data A = A { field :: String }
    data B = B { field :: String }
  2. It's partial. The following code will result in a runtime error:

    data A = A1 { field1 :: String } | A2 { field2 :: String }
    
    main = print $ field1 $ A2 "abc"
  3. It does not allow you to use the same field name for different types across constructors:

    data A = A1 { field :: String } | A2 { field :: Int }

This proposal approaches all the problems above and also a fourth one, which is unrelated to the current record system: it allows one to avoid declaration of intermediate types (see details below).

Gentlemen, I want you to meet,

##Anonymous Records

When a record-syntax is used in Haskell it's almost always a single-constructor ADT. A question rises then: why use ADT when you don't need its main feature (i.e., the multiple constructors)? This main feature is actually the root of the second and the third problem of record-syntax from the list above. In such situations one doesn't actually need ADT, but something more like a tuple with ability to access its items by name. E.g.:

f :: (a :: Int, b :: String) -> String
f rec = rec.b ++ show rec.a

application:

f (a = 123, b = "abc")

So now you think "Okay, but how about naming it?". Well, not a problem at all - use the existing type-construct:

type TheRecord = (a :: Int, b :: String) 

Now, about the avoidance of intermediate types:

type Person = (name :: String, phone :: (country :: Int, area :: Int, number :: Int))

See? No need to declare separate types for inner values. But, of course, if you need, you still can:

type Phone = (country :: Int, area :: Int, number :: Int)
type Person = (name :: String, phone :: Phone)

We can nicely access the deeply nested fields, e.g.:

personCountryCode :: Person -> Int
personCountryCode person = person.phone.country

We can make the function above polymorphic, by letting it work on all records containing a field phone with a record containing a field country:

recordPhoneCountry :: (phone :: (country :: a)) -> a
recordPhoneCountry record = record.phone.country

Okay. What about the type ambiguity? E.g., in the following the Person is actually the same type as Company:

type Person = (name :: String, phone :: Phone)
type Company = (name :: String, phone :: Phone)

Easily solvable with a help of newtype:

newtype Person = Person (name :: String, phone :: Phone)
newtype Company = Company (name :: String, phone :: Phone)

What about ADTs? Again, easy:

data Product = Tea (brand :: Company)
             | Milk (brand :: Company, fatness :: Float)
             
productBrand :: Product -> Company
productBrand (Tea record) = record.brand
productBrand (Milk record) = record.brand

Now, the beautiful fact:

This solution does not conflict with any existing feature of Haskell! As the examples show, it easily fits into the language as an extension. It can peacefully coexist with the existing record system of ADTs. Hence a complete backwards compatibility with old codebase. There's also a potential for many other additional features.

##Research Turns out, there's been plenty of related proposals:

There even exist implementations in some Haskell dialects:

There is a devoted page on related research at GHC wiki:

##Links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
机翻是什么意思 口且念什么 大蒜不能和什么一起吃 一身傲骨是什么意思 c1和c2有什么区别
两肺间质性改变是什么意思 perrier是什么水 葡萄籽什么牌子效果好 床上出现蜈蚣什么原因 胸围85是什么罩杯
茂密的枝叶像什么 8月7号是什么星座 叫人挪车打什么电话 拔智齿后可以吃什么 眼睛看什么科
c14呼气试验是检查什么的 肌肉萎缩看什么科 前庭综合症是什么病 洗衣机什么牌子最好 甲肝抗体阳性代表什么
刹是什么意思xinmaowt.com 为什么来月经会拉肚子hcv8jop8ns0r.cn 什么叫飞机杯hcv8jop5ns7r.cn 夏天感冒咳嗽吃什么药hcv9jop6ns7r.cn 后脑勺疼吃什么药hcv9jop2ns3r.cn
428是什么意思hcv9jop5ns0r.cn 乙肝核心抗体阳性是什么意思bjcbxg.com 昆仑玉什么颜色最贵hcv8jop1ns6r.cn 摩羯属于什么象星座hcv8jop5ns2r.cn 女生适合什么工作hcv9jop0ns5r.cn
申是什么生肖hcv9jop6ns6r.cn 霍山石斛有什么作用hcv9jop6ns0r.cn 金棕色是什么颜色hcv8jop4ns1r.cn 内痔有什么症状与感觉hcv9jop8ns0r.cn 肩周炎吃什么药好hcv8jop8ns6r.cn
才情是什么意思hcv9jop4ns7r.cn 力挽狂澜是什么意思creativexi.com 咽炎要注意什么饮食hcv9jop5ns4r.cn 因公殉职是什么意思hcv8jop8ns1r.cn 成五行属性是什么hcv7jop5ns2r.cn
百度 技术支持:蜘蛛池 www.kelongchi.com