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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Candy – a minimalistic functional programming language

79 点作者 microflash大约 1 年前

10 条评论

tromp大约 1 年前
&gt; Dividing by a string fails during compilation with a type error, while dividing by zero only fails during runtime. In the mathematical sense, there&#x27;s no fundamental difference between these cases – division is only defined for divisors that are non-zero numbers.<p>It seems there is a fundamental difference: zero-ness is a value property while number-ness is a type property. That makes the latter trivial to check at compile time.<p>&gt; That&#x27;s why we eliminate the border between compile-time and runtime errors – all errors are runtime errors.<p>That seems like a step back from having an editor type-check your code.<p>&gt; By crafting high-quality tooling with dynamic analyses such as fuzzing, we try to still be able to show most errors while you&#x27;re editing the code.<p>But fuzzing takes more resources than typechecking. I&#x27;d prefer to always do the latter, and make the former optional , as Haskell does with QuickCheck.
评论 #39496300 未加载
评论 #39494651 未加载
评论 #39495971 未加载
chrisjj大约 1 年前
&gt; we eliminate the border between compile-time and runtime errors – all errors are runtime errors.<p>&gt; we try to still be able to show most errors while you&#x27;re editing the code<p>This is not eliminating a border. It is adding a border strip between edit and run - covering all of compile.<p>And &quot;all errors are runtime errors&quot; tasks the compiler with compling erroneous code just to serve runtime detection.
breck大约 1 年前
&gt; Fuzzing instead of traditional types. In Candy, functions have to specify their needs exactly. As you type, the tooling automatically tests your code with many inputs to see if one breaks the code<p>This is a neat idea and the screenshots make it look fun. There are a few features that once you&#x27;ve gotten used to, become hard to live without (syntax highlighting, autocomplete, unit tests, etc). I could see how this real-time fuzzing approach might be one of those. Would be fun to try.
评论 #39494888 未加载
librasteve大约 1 年前
In almost all (strongly typed) languages, there is still a need for runtime checks like divide by zero and array bounds checks. Certainly languages like Rust &amp; Haskell bring a high level of static analysis and that is good when you are relying on the tool for memory safety.<p>Personally I prefer gradual type systems that need less up front wrestling so that the coding process is more productive, more time can be spent on tuning the design rather than “finally I made it work” acceptance of compiler driven design. Such languages such as Python, Raku use GC for safety so not perfect for embedded or OS type tasks but easier on the brain.<p>I mentioned Raku since it has extensive runtime type support which allows code like:<p><pre><code> subset Zero of Int where * == 0; subset NonZero of Int where * != 0; multi infix:&lt;div&gt;(Int \a, Zero \b) {warn “you dolt”; Inf} multi infix:&lt;div&gt;(Int \a, NonZero \b) {a div b} </code></pre> So Larry Wall chose to leverage a runtime typesystem to make it easier to write and maintain code rather than go down the straitjacket route.
评论 #39495291 未加载
评论 #39499712 未加载
TOGoS大约 1 年前
Neat! The idea that &#x27;types are just constraints on values that happen to be checked at compile-time&#x27; is something I&#x27;ve been thinking about for a long time. I&#x27;ve been thinking about building a Scheme-like language on the same principle.<p><pre><code> (define (my-function some-number) (assert (is-int some-number)) (assert (is-nonzero some-number)) (...body of function goes here)) </code></pre> That way you can start with a dynamically typed language and slowly add type information (and any other constraint you want) without having to modify the syntax. A Sufficiently Advanced Compiler may be able to detect problems that e.g. `javac` wouldn&#x27;t. But I&#x27;m probably repeating what the Candy devs already said in their readme.<p>The thing holding me back, aside from general indecisiveness and getting stuck in bootstrapping loops (I immediately get annoyeed with existing build tools and want to write my own...in my language that doesn&#x27;t exist yet) is that I wonder if I should learn about dependent types, first, in case it totally changes my approach. I&#x27;ve had a PDF of The Little Typer open to some page in chapter 2 for months, now.<p>Another concept I want to embed is that there are no fundamental structural types. e.g. anything that acts like a list is a list. What you <i>really</i> want to know is the &#x27;color&#x27;[1] of values, i.e. &#x27;what does this value MEAN&#x27;. Because you can represent anything as a list, and especially in dynamically-typed languages, it&#x27;s not always obvious if you&#x27;re supposed to e.g. interporet a list as a list, or as something else, represented by the list. &quot;You must beware of shadows&quot;, as they say. Maybe what I want is &#x27;dynamic structural types but static coloring&#x27;.<p>[1] term borrowed from the JavaScript world, often referred to as the &#x27;function coloring&#x27; problem, though it&#x27;s not really about the function so much as the values they take and return. &quot;Is this promise you just passed me standing for itself, or did you want me to calculate something based on the promise&#x27;s result value?&quot;
评论 #39496709 未加载
runeblaze大约 1 年前
It might be fun to besides doing fuzzing, use other software correctness &#x2F; formal methods tools such as abstract interpretation or type systems to report run-time errors. I mean, fuzzing will not detect all runtime errors, so the formal methods crowd might suggest to just throw all your tools in the toolbox to maximize run-time error elimination.<p>Delegate everything to fuzzing is fun though (fitting for the name &quot;candy&quot; and the minimalistic premise).
评论 #39495024 未加载
评论 #39494474 未加载
quag大约 1 年前
I have take a weakness for languages like Candy. A word of warning for those eager to dive in like myself. Candy seems to require a nightly build of Rust from 2024-02-22 (that&#x27;s two days ago). After building, it gave me a 157MB binary that either seems to panic or print nothing when I run the examples. I assume the only way to really use it right now is from VSCode, and trying to run the CLI tool (as I did) just doesn&#x27;t work. I&#x27;d love to give it a go, but I might have to wait a few more weeks.
评论 #39499540 未加载
pona-a大约 1 年前
Fuzz testing seems surprisingly powerful as part of an IDE and doesn&#x27;t require any new annotation but seems to waste a ton of resources... I wonder if someone developed an algorithm for most efficiently breaking your assertions, perhaps even with a pre-fitted probabilistic heuristic guiding the search.
josephcsible大约 1 年前
&gt; That&#x27;s why we eliminate the border between compile-time and runtime errors – all errors are runtime errors.<p>That&#x27;s the opposite of what I want. I want as many errors as possible to be compile-time errors, so that I know I&#x27;ll catch them all during development instead of as bugs in production.
nmca大约 1 年前
Wonderful new stuff.<p>I heard it suggested recently that it would be interesting to build a static analysis system around proving that code was wrong (as opposed to proving that certain classes of bugs were missing). Fuzzing seems like one reasonable approach. Love the editor integration too.