为什么类型类很难实现? [英] Why were type classes difficult to implement?

查看:73
本文介绍了为什么类型类很难实现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个演示文稿的幻灯片30/78上,Simon建议实施类型班级在开始时是一种绝望。是否有人知道这是为什么?

解决方案

我想我是为数不多的第一手体验的人之一很难,因为我在没有现有技术的情况下以hbc实现它。

因此,Wadler& Blott论文清楚地表明,类型检查是Hindley -Milner类型检查,并且在运行时你应该传递字典。从这到实际的实施是一个相当大的步骤。理解困难的一个好方法是从Wadler-Blott论文开始真正实现它。

首先,你需要想出一个类型检查器的概念不仅检查类型而且改变程序;在进行类型检查时插入证据(字典)。您还需要弄清楚如何使用实例声明作为推理系统来构造旧的字典。



回想起来,这一切似乎都很明显,但请记住,既然那个时候有很多有解释的论文。理解如何从一篇论文中做点什么与将它放在首位是非常不同的。



另外,你希望类型类能够合理高效地导致它自己的一套问题。


On slide 30/78 of this presentation, Simon suggests that implementation of type classes was a "despair" at the beginning. Is anybody aware why that was?

解决方案

I guess I'm one of the few people who have first hand experience of why it was hard, since I implemented it in hbc when there was no prior art.

So what was clear from the Wadler&Blott paper was that type checking was an extension of Hindley-Milner type checking and that at runtime you should be passing dictionaries around. From that to an actual implementation is a rather big step. A good way to understand the difficulty is to actually implement it starting from just the Wadler-Blott paper.

First, you need to come up with the idea of a type checker that not only checks types but also transforms the program; inserting evidence (dictionaries) while type checking. You also need to figure out how to construct new dictionaries from old ones using the instance declarations as an inference system.

It might all seem obvious in retrospect, but remember that since that time a lot of papers with explanations have been written. Understanding how to do something from a paper is very different from coming up with it in the first place.

Furthermore, you want type classes to be reasonably efficient which leads to its own set of problems.

这篇关于为什么类型类很难实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆