Live data from Hacker News

Haskell vs. Clojure (2014)

gist.github.com

31–40 of 55 posts

Re: Haskell vs. Clojure (2014)

#31
post #20
post #7

Earlier quoted context omitted.

> ... Clojure is fine (though any other Lisp would arguably be better than Clojure). Care to elaborate why you think any other Lisp is better than Clojure? I would like to hear your arguments.

Clojure has neither the cool constructs of CL (CLOS, conditions) nor the minimal design and fantastic set of control primitives of Scheme. In fact it has no significant advantage over Scheme aside from running on the JVM, and a few disadvantages (recur, why TF are lambda lists vectors?, etc.). It's different enough to be weird and annoying, but the differences aren't advantageous enough to make me want to switch: Sch…

I mostly agree with you, but I think the out-of-the-box immutable data structures and sugar around around maps are very nice compared to the out-of-the-box scheme/racket experience.

Re: Haskell vs. Clojure (2014)

#32
I know barely enough haskell, passively, to dislike quite a lot of this code (like really, 3 lines on 3 places, just to case on a maybe to throw an error? w/a just calling fromMaybe or even fromJust? and manual instances??) - but, could someone more experienced suggest a saner one?

Re: Haskell vs. Clojure (2014)

#33
post #31
post #20

Earlier quoted context omitted.

Clojure has neither the cool constructs of CL (CLOS, conditions) nor the minimal design and fantastic set of control primitives of Scheme. In fact it has no significant advantage over Scheme aside from running on the JVM, and a few disadvantages (recur, why TF are lambda lists vectors?, etc.). It's different enough to be weird and annoying, but the differences aren't advantageous enough to make me want to switch: Sch…

I mostly agree with you, but I think the out-of-the-box immutable data structures and sugar around around maps are very nice compared to the out-of-the-box scheme/racket experience.

I'm a fan of the out of the box immutable data structures and like the sugar, though you can get both in Lisp if you want. (Presumably Racket as well.) Lisp has everything, and more, though sometimes you have to work for it. I do enjoy Clojure's interop with the JVM, but that along with the community producing interesting things (this includes ClojureScript) are the primary reasons I care about Clojure at all. On the nice-to-work-with side of things I really enjoy that it was designed by one person rather than a standards committee from decades ago, it feels fresh working with it, but if you stranded me on an island and gave me one language to have for the rest of time I'd pick Lisp for its power.

Re: Haskell vs. Clojure (2014)

#34

    flatten :: ByteString -> [ (String, Int, Int, String) ]
    flatten json = case decode json of
      Nothing -> []
        -- Type inference here can infer that we're using `val` as
        -- :: HashMap String (HashMap String (HashMap String String))
      Just val ->
        let books = ["Genesis", "Exodus" {- ...and so forth -} ]
        in [ (book, chNum, vsNum, verse)
              -- for every book in the list of books...
           | book 
Okay, this isn't as type-safe or signed-in-triplicate as the supplied Haskell solution, but if we're comparing size-to-size, then this is pretty terse while also avoiding partial functions (the supplied Haskell solution uses read, which can throw an error if we happen to have a non-numeric key in the wrong place) and still working within the restrictions of what was given.

Re: Haskell vs. Clojure (2014)

#35
post #21

Earlier quoted context omitted.

Clojure's immutable types mean just that—the values are immutable (e.g., in CL you could do (defvar x 42) (setf x 84), but in Clojure the equivalent is not allowed). But there are many more side effects than changing variables. Clojure makes no guarantees that a given function is referentially transparent, nor does it promise that a given function doesn't write to stdout/stderr, read from stdin, change the file syste…

Not arguing that the following method can be trusted as much as in Haskell but properly used also prevents this kind of scenario: https://clojuredocs.org/clojure.core/io℅21 The 'io!' macro marks a code block to have side effects which prevents using it in a STM transaction as 'dosync' might need to execute the functions multiple times in case of conflicts during the optimistic locking.

> properly used

In the sense C programmers use the term? Why should humans be trusted with identifying all operations that can't be safely performed within a transaction?

Re: Haskell vs. Clojure (2014)

#38
post #18
post #7

Earlier quoted context omitted.

> ... Clojure is fine (though any other Lisp would arguably be better than Clojure). Care to elaborate why you think any other Lisp is better than Clojure? I would like to hear your arguments.

Not the GP, but for quick things I prefer CL because: * TIMTOWTDI. Doing everything with map/reduce/filter is great, but sometimes it's more direct to just use the LOOP macro. Immutability is great, but sometimes it's way faster to just SETF something (and not have to worry about atoms). * Batteries (more) included. IME, I find myself needing to use third-party libraries sooner with Clojure than with CL. Also, QuickL…

How is it more direct to use loop? As someone who has been writing production clojure for nearly 5 years I usually only see loop macro used by devs coming from oop because that's a more comfortable pattern for them. I have rarely needed to use it.

As far as collections go, there's filter, remove, reduce, and various take functions. I don't see the deficiency.

Debugging is still an issue, but I personally don't find it too difficult... probably because I'm used to it.

Re: Haskell vs. Clojure (2014)

#39

flatten :: ByteString -> [ (String, Int, Int, String) ] flatten json = case decode json of Nothing -> [] -- Type inference here can infer that we're using `val` as -- :: HashMap String (HashMap String (HashMap String String)) Just val -> let books = ["Genesis", "Exodus" {- ...and so forth -} ] in [ (book, chNum, vsNum, verse) -- for every book in the list of books... | book Okay, this isn't as type-safe or signed-in-…

One thing true of all bugs, it passed the type checker.

Re: Haskell vs. Clojure (2014)

#40
scala?

  #!/usr/bin/env amm
  
  import $ivy.`io.circe::circe-core:0.5.1`
  import $ivy.`io.circe::circe-generic:0.5.1`
  import $ivy.`io.circe::circe-parser:0.5.1`
  
  import io.circe._, io.circe.generic.auto._, io.circe.parser._, io.circe.syntax._
  
  val bookOrder = Array("Genesis", "Exodus", /* and so forth */).zipWithIndex.toMap
  
  type Bible = Map[String, Map[Int, Map[Int, String]]]

  val bible = /* load the json file */

  decode[Bible](bible).map { parse =>
    (
      for {
        (bookName, book) 
        (bookOrder.get(b._1), b._2, b._3, b._4)
      }
  }.foreach(_.foreach(println))
Post reply on HN