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.

Loop: a programming language for the JVM inspired by Haskell and Ruby

87 pointsby dhanjialmost 13 years ago

20 comments

fusiongyroalmost 13 years ago
Syntax looks very clean, but probably more like CoffeeScript mixed with Ruby. "Inspired by Haskell" is going a bit far. You took pattern matching and `where` and none of the semantics.<p>Object patterns are absolutely awesome. Every OOP/FP hybrid ought to have that. Especially if you're not going to support algebraic data types. That point is worth bringing up, though: are they missing because of the presents of objects? I'm concerned about the interaction between pattern matching, duck typing and Java's static typechecker. Based on a quick glance, it's hard to see what that interaction is going to be like. At the very least, it does raise the question: what makes the pattern matching on lists and other built-in types special? In Haskell, for example, there's nothing magic about the cons operator and lists; it's just regular pattern matching on algebraic types.<p>I suspect your magic Nothing type is also necessary to make object pattern matching powerful, and I have some concerns about this kind of null safety. I wonder if programs are going to wind up turning into "gray goo" of Nothing, and what the debug scenario is for that case.<p>Exception handling looks a bit odd to me. Maybe it all works out in the end, but it looks like you're going to wind up with code like this:<p><pre><code> foo(x) except handler where handler(e) =&#62; IOException : e.stuff ... </code></pre> I think this is going to wind up being a bit gassy for local exception handling, where in Java you would see something like this, that avoids the intermediate name:<p><pre><code> try { foo(x); } catch (IOException e) { e.stuff } ... </code></pre> Is it going to look better with closures?<p><pre><code> foo(x) except @(e) -&#62; { IOException : e.stuff ... } </code></pre> It's probably fine, but I dunno, most languages use more syntax in this area.<p>Overall, this is fairly impressive. It looks a bit like the greatest hits of Ruby and ML. The JVM has been host to a surprising number of interesting languages lately, and this is clearly one of the better recent offerings. Definitely worth a deeper look.
评论 #4041122 未加载
Tyr42almost 13 years ago
I take issue with<p><pre><code> Haskell programmers may be familiar with this as a do block, and for Schemers, this is the equivalent of a begin sequence. However, unlike Haskell, in Loop, a sequence is guaranteed to execute in order. </code></pre> A do block is syntactic sugar over &#62;&#62;= (bind) and is monadic in nature. And the IO monad (which is relevant to the example that involved printing things.) is a construct which guarantees that the parts will execute in order. That's kinda the point. That he got it wrong makes me not trust the language. He shouldn't claim to have been "Inspired by Haskell" if he doesn't really know it.<p>Also in Haskell the pattern [x:xs] matches a list with one element, which is a list with at least one element, so [[1,2,3]] (== (1:2:3:[]):[]) gets matched with x = 1 and xs = [2,3]. That differs from loop's pattern matching. But [x] still matches a list with only one element. What does [x:[]] match? If you are going by [x:xs] matches [1] with x = 1 and xs = [], then surely [x:[]] will match as well.<p>Also, if you are making a functional programming language, you know one that uses recursions instead fo for loops, why do you call it Loop? I didn't see one loop in any of the examples. It's just silly.<p>EDIT: Oh, and if Nothing really is a subtype of everything, then 5 + Nothing should typecheck right? Not " It is a type error to attempt to compute with Nothing." Since Nothing is a Integer, since it subtypes everything. I don't understand. Is + special in hating Nothing? Nothing.add(5) would return Nothing, right? So why not Nothing + 5. Oh, but wait, Nothing is a subtype of string, so Nothing + 5 means string concatenation, right? You did say a + b where a is a string casts b to a string, didn't you? It's inconsistent and I don't think it has the proper semantics.
评论 #4043093 未加载
acalmost 13 years ago
I think it's quite misleading to list Haskell in the title: the only common thing between Loop and Haskell that I've found is pattern matching, and that's not even exclusive to Haskell -- other languages have it. Besides, it's not clear from the intro that Loop's pattern matching is as powerful as Haskell's (especially with all the extensions). Finally, pattern matching is really a syntactic sugar over the case/switch construct present in many, many languages. Although, I liked the type-patterns.
评论 #4040756 未加载
Patient0almost 13 years ago
Thanks a lot for sharing this - particularly the full source code of your implementation. It looks very clean and well written.<p>I personally like that you wrote your own recursive descent parser and lexer rather than using some tool to generate one. This is my preference too.<p>The result is that the source code makes for a great reference for anyone thinking of implementing a language on top of the JVM.<p>Pay no heed to the "bah humbug" comments elsewhere on this story - I think what you've done is great.
swangalmost 13 years ago
Haven't had the chance to download and look through it but an example caught my eye.<p>Was anyone else confused that this,<p># filter list =&#62; [ 'ipod', 'ipad', 'iphone' ]<p>('i' + p) for p in ['mac', 'pod', 'pad', 'phone'] if p.startsWith('p')<p>applies a filter against the list, rather than limit what gets prefixed with an 'i'?<p>I'm assuming then there's some code to keep the mapping and the entire list as well. Something like this?<p>('i' + p) if p.startsWith('p') for p in ['mac', 'pod', 'pad', 'phone']<p>It just seemed surprising to me that an if statement can cause a change in the list length.<p>Edit: Ah this seems to be how filtering works in python
评论 #4040451 未加载
virmundialmost 13 years ago
Perhaps this isn't the place for the question, but I'll ask anyway. Is there any JVM-based language that excludes any code from being compiled that is not directly implemented in that language? For example, any code that would deny the use of java.io or java.lang?<p>The reason I ask is because Clojure and Scala both suffer from the ability to call legacy code. While some think this is a good idea, it makes the whole scalable, safe/functional paradigm completely unstable. Is there any language out there that forces the developer to use only things written in the specific language its since that would be the only safe platform?
评论 #4041629 未加载
perfunctoryalmost 13 years ago
&#62; Closures, or anonymous functions, are quite useful...<p>Apparently these days one doesn't need to know the difference between closures and anonymous functions to be a language designer.
eta_carinaealmost 13 years ago
The name is unfortunate, especially when the documentation sometimes omits to capitalize "Loop", which introduces even more confusion than there already is.
评论 #4041688 未加载
jdefargealmost 13 years ago
Good to know there are newer takes on JVM based languages! I like its minimalist design as opposed to being a kitchen sink language. Good luck!
chrisbroadfootalmost 13 years ago
<i>Being functional in nature, Loop doesn't have any of the baggage of the host platform (Java)</i><p>I don't see much that's functional in this language, but this statement made me laugh. It looks like a lot of Java's baggage is still alive and well in this language, like exceptions (quite un-Haskell-like)
评论 #4040965 未加载
jordibunsteralmost 13 years ago
Looks great. I wonder why the author went for a specific syntax for interned strings, as opposed to doing what Java does (automatically interning String literals).
dardiealmost 13 years ago
Another cool language from the past, 'nice', had a similar issue that sentenced it to obscurity. A totally ungooglable name :-(
评论 #4041787 未加载
perfunctoryalmost 13 years ago
<p><pre><code> Sequences increment(num) -&#62; print(num), num + 1 </code></pre> This is considered to be one of the worst parts of Erlang syntax. Too bad loop borrows it.
DaNmarneralmost 13 years ago
Now available on Arch Linux via AUR: <a href="https://aur.archlinux.org/packages.php?ID=59624" rel="nofollow">https://aur.archlinux.org/packages.php?ID=59624</a>
warmfuzzykittenalmost 13 years ago
Capital-J Java as in 'Java -version'? Examples should be tested. @ is heavily overloaded. Other than that, worth a second look.
zsergealmost 13 years ago
I wish it was ported to Android platform.
padrian2ssalmost 13 years ago
there is nothing like out there resemblance with haskell :D
zsteacyalmost 13 years ago
Is awesome!
awesomesaucesalmost 13 years ago
Hmm, going to have to look into this later.
eta_carinaealmost 13 years ago
&#62; Polymorphism in this instance is simply allowing you to call the same function with an integer and string respectively.<p>Er... no, that's not polymorphism, that's overloading.
评论 #4040833 未加载