Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
136 views
in Technique[技术] by (71.8m points)

haskell - Why were type classes difficult to implement?

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?

question from:https://stackoverflow.com/questions/9602176/why-were-type-classes-difficult-to-implement

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...