News for hackers. Stuff that matters.
Re:Kronos Haskell by marcosdumay on Wednesday March 25, 2015 @01:56PM (#9264658)
What, a Haskell program that launches 3 threads and coordinates them with inter-thread communication is harder to read than an Ada Hello World? Who would have tought!

The equivalent in Haskell to your Ada program is:

main = putStrLn "Hello, World!"

I don't even think about taking the time to write the equivalent in Ada to the Haskell program you posted.

Re:Kronos Haskell by tormeh on Wednesday March 25, 2015 @06:48PM (#9266564)
I'm no good at Ada, but I like the way it's syntax tries to guide you through reading the program. Now for something of comparative complexity in Clojure:

  (def x (ref 1))

  (defn increment [i]
    (if (> i 0) 
      (
        (dosync
          (alter x inc)
        )
        (Thread/sleep 1)
        (increment (- i 1))
      )
    )
  )

  (defn decrement [i]
    (if (> i 0)
      (
        (dosync
          (alter x dec)
        )
        (Thread/sleep 1)
        (decrement (- i 1))
      )
    )
  )

  (defn printref [i]
    (if (> i 0) 
      (
        (dosync
          (println (format "in printref %d" @x))
        )
        (Thread/sleep 1)
        (printref (- i 1))
      )
    )
  )

  (future
    (increment 10)
  )

  (future
    (printref 15)
  ) 

  (future
    (decrement 10)
  )
Isn't this much nicer? It's not immediately obvious that x is an atomic variable, but aside from that it's a lot better than the Haskell example. It took me along the lines of 2-3 hours from never having touched a Lisp to writing this.
Re:Kronos Haskell by sgk284 on Thursday March 26, 2015 @03:23AM (#9268199)
Here is the Haskell equivalent of your Clojure code:

    import Data.IORef
    import Control.Concurrent

    increment _ 0 = return ()
    increment x i = do
        alter x succ
        threadDelay 1000
        increment x (i - 1)

    decrement _ 0 = return ()
    decrement x i = do
        alter x pred
        threadDelay 1000
        decrement x (i - 1)

    printref _ 0 = return ()
    printref x i = do
        val <- readIORef x
        putStrLn ("in printref " ++ (show val))
        threadDelay 1000
        printref x (i - 1)

    main = do
        x <- newIORef 1

        forkIO (increment x 10)

        forkIO (printref x 15)

        forkIO (decrement x 10)

        threadDelay 100000

    -- This is just a helper to more closely match the clojure
    alter x fn = atomicModifyIORef' x (\y -> (fn y, ()))
I'd argue the Haskell is even nicer.
Re:Kronos Haskell by BasDirks on Thursday March 26, 2015 @03:01AM (#9268161)
No this is not much nicer.