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.

Clojure's core.typed vs Haskell

120 pointsby llambdaover 11 years ago

10 comments

freyrs3over 11 years ago
A simple program is an interesting comparison, but it's kind odd to consider this to compare the whole typesystem. It's hard to understate that GHC has a /big/ typesystem and has had a significant amount of research done in it over the past 10 years and a a result there are a lot of very powerful non-trivial typing constructs. I think the real testament to the power of Haskell's typesystem is how well inference still works even in the presence of most of these non-trivial extensions.
评论 #6470429 未加载
tikhonjover 11 years ago
If you really want it, you can get <i>safe</i> dynamic typing in Haskell using the Data.Dynamic module. However, since you <i>don&#x27;t</i> really want it, it&#x27;s a library that isn&#x27;t introduced in basic tutorials.<p>This gives you a pragmatic equivalent to no-check, but is almost never used in practice because it turns out to be unnecessary.
评论 #6472472 未加载
评论 #6472224 未加载
zeckalphaover 11 years ago
I&#x27;d be curious to see how Typed Racket compared, too.
评论 #6469894 未加载
评论 #6469893 未加载
masklinnover 11 years ago
&gt; As seen at the top, it was necessary to annotate mod. It has the no-check flag on it, which is basically how you tell core.typed to just take your word on this one. That&#x27;s something you can&#x27;t do in Haskell, but I&#x27;m not sure whether or not that&#x27;s a good thing.<p>Isn&#x27;t the reason why you need to do it because you&#x27;re importing a non-typed symbol? Wouldn&#x27;t the only situation where you&#x27;d need to do that in Haskell be at FFI?<p>(and a nitpick: `putStrLn $ show` can be replaced with a simple `print` call)
评论 #6469804 未加载
adestefanover 11 years ago
&gt; Integer is less useful as a type than hoped. AnyInteger seems to be more permissive, and works more often. I&#x27;m sure there is a good reason for this.<p>This is with about 15 minutes of looking at core.typed. Isn&#x27;t this because the type Interger is actually java.lang.Integer, but (type 1000) is java.lang.Long?<p>Also, AnyInteger isn&#x27;t that permissive. It&#x27;s defined as (U Integer Long clojure.lang.BigInt BigInteger Short Byte). The big difference would be that Haskell&#x27;s Int is bounded so AnyInteger is more like Haskell&#x27;s Integer.
评论 #6470733 未加载
jahewsonover 11 years ago
The Haskell could use a list comprehension...<p><pre><code> divBy x y = y `mod` x &#x2F;= 0 divBy3or5 x = divBy 3 x || divBy 5 x euler1 n = sum [x | x &lt;- [0..n], divBy3or5 x] main = print $ euler1 1000 </code></pre> Personally, I&#x27;d switch out lines 2 and 3 to:<p><pre><code> euler1 n = sum [x | x &lt;- [0..n], divBy 3 x, divBy 5 x] </code></pre> Compared with the Clojure (correct me if I&#x27;m wrong):<p><pre><code> (defn euler1 [n] (reduce + (filter (fn [x] (or (div-by 3 x) (div-by 5 x)))) (range n))) </code></pre> Edit: Note - Clojure code doesn&#x27;t fit into a HN one-liner.
评论 #6470658 未加载
lelfover 11 years ago
Apples vs vacuum cleaners
lysiumover 11 years ago
Is this (at the end of problem 1)<p><pre><code> (defn div-by [x y] (== 0 ))(mod y x) </code></pre> a typo or a Clojure feature?
IsTomover 11 years ago
Not being familiar with core.typed: does it support parametric polymorphism? Can you dispatch based on types (e.g. typeclasses)?
评论 #6471623 未加载
segmondyover 11 years ago
What a waste of an article. 8 lines of code for haskell, 19 lines for clojure. The problem is easily solved in one line. I seriously don&#x27;t care that&#x27;s he comparing core.type, when you start trying to write langauges the same way, you lose the advantage that they provide.<p>1 line of python.<p>print sum(filter(lambda x: (x % 3 == 0) or (x % 5 == 0), range(1, 1000)))<p>clojure<p>(apply + (filter #(or (= 0(mod % 3)) (= 0(mod % 5))) (range 1 1000)))
评论 #6470748 未加载
评论 #6470797 未加载
评论 #6470806 未加载
评论 #6470739 未加载
评论 #6473134 未加载