TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Typed Lisp, A Primer (2019)

77 点作者 tagfowufe超过 2 年前

10 条评论

PaulHoule超过 2 年前
I have hacked off and on on this<p><a href="https:&#x2F;&#x2F;github.com&#x2F;paulhoule&#x2F;ferocity">https:&#x2F;&#x2F;github.com&#x2F;paulhoule&#x2F;ferocity</a><p>which lets you write extended Java in a lispy syntax. It generates stubs for the standard library and other packages you choose, unerasing types by putting them into method names. It works pretty well with IDEs but there are still problems w&#x2F; type erasure such that some kinds of type checking can&#x27;t be done by the compiler working directly on the lispy Java, probably I wouldn&#x27;t implement newer features such as pattern matching that are dependent on type inference to work, though lambda definitions are feasible if you give specific types.<p>The &#x27;extended&#x27; bit was almost discovered instead of invented in that it is pretty obvious that you need quote and eval functions such that you can write lispy Java programs that manipulate Java expressions. Said expressions can be evaled at runtime with a primitive interpreter or incorporated into classes that are compiled w&#x2F; Javac. The motivation of the thing was to demonstrate Java-embedded-in-Java (an ugly kind of homoiconicity) and implement syntactic macros from Java which I think that prototype proves is possible but there is a lot more to be done on it to be really useful. Enough has been implemented in it right now in that you can use it to write the code generator that builds stubs. It might be good for balls-to-the-walls metaprogramming in Java but I think many will think it combines all the worse features of Java and Lisp.
shadowgovt超过 2 年前
Article makes one error that is mostly correct but can trip someone up in corner cases. In section 2.5, article makes the assertion `(the τ e) ≈ (or (check-type e τ) e)`<p>This may be true in some implementations, but the actual defintion of the `(the)` special operator is that if e is not type τ, the behavior of `(the τ e)` is undefined! Crashing when the type is determined to mismatch is one allowed result, but `the` is also the language&#x27;s &quot;escape hatch&quot; to permit implementations to improve performance by throwing away runtime type information, at which point abusing types will crash in surprising ways.
vindarel超过 2 年前
&gt; Augment Lisp with functional Haskell-like type declarations ;-)<p>Since the article&#x27;s publication, this is now possible with the industrial-grade Coalton: <a href="https:&#x2F;&#x2F;github.com&#x2F;coalton-lang&#x2F;coalton&#x2F;">https:&#x2F;&#x2F;github.com&#x2F;coalton-lang&#x2F;coalton&#x2F;</a>
评论 #34599490 未加载
评论 #34597166 未加载
评论 #34601799 未加载
aidenn0超过 2 年前
With the disclaimer that cl:satisfies makes the tun-time type-system turing complete (and no implementation I know of chacks cl:satisfies at compile time), the compiler-available types are strictly non-recursive.<p>For example, you cannot define a type that means &quot;A List of type X&quot; because that requires recursion i.e. this is not allowed:<p><pre><code> (deftype typed-list (x) `(cons ,x (or (typed-list ,x) null))) </code></pre> So one must either declare the type of the loop-local variable(s) (when iterating) or the first N item(s) of a list (when recursing), which is a bit unfortunate. SBCL, in particular, does a great job of inferring types at compile time with just a few annotations, but code that is optimizer-friendly is made significantly more ugly by this. Or, you know, people just end up using arrays for everything.
runevault超过 2 年前
I&#x27;ve been thinking about typed lisp a bit lately since I started messing with CL again, and I admit the point about lists as code hadn&#x27;t crossed my mind as something you have to deal with for any typing attempts. If you tried to make a &quot;fully static typed lisp&quot; likely you&#x27;d need a few holes for areas like that where they don&#x27;t make sense. Well that or do the shenanigans things like c# do for param arrays where it is just an array of objects.<p>Mind you I feel like over time we are seeing dynamic and static typing converging more and more. Python type annotations are a thing to some degree I know, while c# a while back added the dynamic type.
评论 #34597205 未加载
评论 #34596814 未加载
评论 #34596892 未加载
评论 #34597656 未加载
Pet_Ant超过 2 年前
There is a similar project for Clojure: <a href="https:&#x2F;&#x2F;github.com&#x2F;typedclojure&#x2F;typedclojure">https:&#x2F;&#x2F;github.com&#x2F;typedclojure&#x2F;typedclojure</a>
retrac超过 2 年前
Yes. With macros and runtime logic it&#x27;s possible to implement just about any type system in Lisp, even an ML-like system. Box everything and use macros to transparently pick it apart and reconstruct your wrapped type objects when you use them. My initial reaction to that whole idea was horror. The inefficiency! But maybe not necessarily. A compiler that understood the type system used, could optimize most of it away. Just like how Haskell or SML compilers do.
评论 #34598364 未加载
评论 #34597740 未加载
neilv超过 2 年前
The Racket platform has Typed Racket, by Sam Tobin-Hochstadt, et al.<p><a href="https:&#x2F;&#x2F;docs.racket-lang.org&#x2F;ts-guide&#x2F;beginning.html" rel="nofollow">https:&#x2F;&#x2F;docs.racket-lang.org&#x2F;ts-guide&#x2F;beginning.html</a>
dang超过 2 年前
Related:<p><i>Typed Lisp, a Primer (2019)</i> - <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=23878612" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=23878612</a> - July 2020 (26 comments)
TOGoS超过 2 年前
&gt; type&#x27;s have always been there<p>As have excessive apostrophe&#x27;s.
评论 #34599507 未加载