TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

I'm not mutable, I'm partially instantiated

225 pointsby tlack6 months ago

12 comments

openasocket6 months ago
I&#x27;ve never used it in production, but I have a deep love of Prolog, just because of how different it is from any other programming language I&#x27;ve used. As a programming paradigm, it found it as eye-opening as functional programming. What I found interesting is that you are operating on logical statements and pattern matching, which often means that the same &quot;function&quot; can be used for multiple different things. For example:<p>append([], List, List).<p>append([Head|Tail], List, [Head|Rest]) :- append(Tail, List, Rest).<p>Is a simple list append function: append(X, Y, Z) is a predicate that match if Z is the list of all elements of X, followed by all elements of Y. You can use it to concatenate lists, of course. But you can also use it to confirm that a particular list start with a particular sequence, or ends with a particular sequence! The idea that the same predicate can be used in multiple different ways is really fascinating to me. I have no idea to what extent that would scale in a large system, but it&#x27;s very interesting
评论 #42077339 未加载
评论 #42079462 未加载
评论 #42077227 未加载
评论 #42079440 未加载
评论 #42086324 未加载
skrebbel6 months ago
Only slightly related, I wish there were a way to express this in run-off-the-mill, imperative&#x2F;eager languages. Eg some way to explicitly mark a class, or something like it, as immutable-but-partially-instantiated. TypeScript supports this a <i>tiny bit</i> by means of its `readonly` keyword which lets you assign a value in the constructor, <i>or in any method called from the constructor</i>. But no later than that! If there was a way to make a field &quot;readonly once_assignable&quot; or something like that, you could do something like in this article (esp if you nest instances of a class that uses this) with an eager language, albeit with a lot more boilerplate (and getters, I assume).
评论 #42088543 未加载
benreesman6 months ago
It’s a beautiful construction. It reminds me a bit of the “canonical” quicksort in Haskell [1].<p>Neither of these implementations is going to be displacing absl::btree_map or std::sort any time soon, but I do feel we have a lot of “room at the bottom” for making simple and elegant code practical on real machines.<p>[1] <a href="https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;7717691&#x2F;why-is-the-minimalist-example-haskell-quicksort-not-a-true-quicksort" rel="nofollow">https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;7717691&#x2F;why-is-the-minim...</a><p>Edit: replaced poorly formatted code with SO link.
skybrian6 months ago
It seems like whether this represents a mutable or immutable data structure depends on the operations you allow. If polling with nonvar() is allowed, couldn’t you see variables mutate as you do more unification? But if it’s not allowed, I guess you get a variable to be defined later?<p>Compare with a Promise. If you can check whether it resolved, you can see it mutate. If the only operation allowed is to await it then from the code’s point of view, it might be considered an immutable reference to the pending result.
评论 #42081739 未加载
anfelor6 months ago
Partially instantiated data structures are also available in Haskell (via Laziness), in OCaml (via tail modulo cons, <a href="https:&#x2F;&#x2F;inria.hal.science&#x2F;hal-03146495&#x2F;document" rel="nofollow">https:&#x2F;&#x2F;inria.hal.science&#x2F;hal-03146495&#x2F;document</a>) and Koka (via constructor contexts, <a href="https:&#x2F;&#x2F;dl.acm.org&#x2F;doi&#x2F;pdf&#x2F;10.1145&#x2F;3656398" rel="nofollow">https:&#x2F;&#x2F;dl.acm.org&#x2F;doi&#x2F;pdf&#x2F;10.1145&#x2F;3656398</a>)
评论 #42079154 未加载
评论 #42078838 未加载
评论 #42077770 未加载
评论 #42086325 未加载
p4bl06 months ago
I don&#x27;t get where the `-` comes from in `key-value` result lines after the &quot;refactoring&quot; title. I feel like it should stay a `,` like at the beginning. Can someone more knowledgeable in Prolog explain that? Is that because of an hidden use of this `to_list` predicate that comes later in the post?
评论 #42076461 未加载
评论 #42076347 未加载
评论 #42077356 未加载
ks20486 months ago
Is &quot;The Art of Prolog&quot; a good place to start with the lanugage?
评论 #42085260 未加载
jfmc6 months ago
A classic library, you can play with it here: <a href="https:&#x2F;&#x2F;ciao-lang.org&#x2F;playground&#x2F;#https:&#x2F;&#x2F;github.com&#x2F;ciao-lang&#x2F;ciao&#x2F;blob&#x2F;master&#x2F;core&#x2F;lib&#x2F;dict.pl" rel="nofollow">https:&#x2F;&#x2F;ciao-lang.org&#x2F;playground&#x2F;#https:&#x2F;&#x2F;github.com&#x2F;ciao-la...</a>
tolerance6 months ago
This is philosophically intriguing.
samweb36 months ago
I am actually working on a logical query language that&#x27;s a successor to prolog here: <a href="https:&#x2F;&#x2F;memelang.net&#x2F;02&#x2F;" rel="nofollow">https:&#x2F;&#x2F;memelang.net&#x2F;02&#x2F;</a>. Any feedback appreciated!
评论 #42077391 未加载
评论 #42080902 未加载
评论 #42080714 未加载
lelag6 months ago
I&#x27;ve noticed quite a lot of Prolog content lately. I don&#x27;t know if it&#x27;s just a case of the Baader–Meinhof phenomenon, but it looks to me that recent article[1] about Prolog being able to improve LLM reasoning abilities renewed some interest in the language.<p>[1] <a href="https:&#x2F;&#x2F;shchegrikovich.substack.com&#x2F;p&#x2F;use-prolog-to-improve-llms-reasoning" rel="nofollow">https:&#x2F;&#x2F;shchegrikovich.substack.com&#x2F;p&#x2F;use-prolog-to-improve-...</a>
评论 #42076249 未加载
评论 #42076445 未加载
评论 #42076379 未加载
bedobi6 months ago
Partial instantiation is cool and all, but tbh I prefer just capturing the initial incomplete attributes in one complete record, pass that around, and then instantiate the real thing when you have all attributes<p><pre><code> data class IncompletePerson(val name: String) data class Person( val name: String, val email: String ) </code></pre> or<p><pre><code> data class Person( val initialAttributes: IncompletePerson, val email: String ) </code></pre> if you want to nest it.<p>if you&#x27;re the type to instead do this<p><pre><code> data class Person( val name: String, val email: String? ) </code></pre> I never want to work with your code. Now, there&#x27;s no disambiguation between the complete object and the incomplete one, I always have to check before doing anything with it, and people will inevitably try send an incomplete object someplace that can&#x27;t handle it and generate bugs.
评论 #42079173 未加载