類型球拍做什麼樣的類型推斷?我發現拍郵件列表下面的代碼片段:Typed Racket的類型推斷如何工作?
The Typed Racket type system contains a number of features that go beyond what's supported in Hindley/Milner style type systems, and so we can't use that inference system. Currently, Typed Racket uses local type inference to infer many of the types in your program, but we'd like to infer more of them -- this is an ongoing area of research.
以上Blurb的使用術語「局部類型推理」,我還聽說「發生打字」用了很多,但我不完全確定這些術語的含義。
在我看來,類型球拍目前使用的類型推斷系統是不必要的弱。這是我的意思的一個例子。下列不類型檢查:
(struct: pt ([x : Real] [y : Real]))
(define (midpoint p1 p2)
(pt (/ (+ (pt-x p1) (pt-x p2)) 2)
(/ (+ (pt-y p1) (pt-y p2)) 2)))
你必須明確地標註midpoint
與(: midpoint (pt pt -> pt))
,否則你得到的錯誤:Type Checker: Expected pt, but got Any in: p1
。爲什麼不能從型號檢驗器得出結論:p1
和p2
必須是是pt
?這是球拍實施方式的一個基本限制(也就是說,由於球拍的某些更高級的類型特徵,這種推理實際上有時是錯誤的),或者這是將來可能實現的東西嗎?
山姆託賓艾施河畔赫希施塔特的博士論文應該有血淋淋的細節:http://www.ccs.neu.edu/racket/pubs/dissertation-tobin-hochstadt.pdf – dyoo