Haskell implementation of longest path algorithm

Compared to the Nim code [https://github.com/logicchains/LPATHBench/blob/master/nim.nim] for a longest path algorithm, Haskell [https://github.com/logicchains/LPATHBench/blob/master/hs.hs] looks horrendously verbose and ugly, even if you ignore the pragmas and imports. Is this idiomatic Haskell style? Could it be clearer, but has to be written that way for performance - although it still takes 3.7x as long as the Nim version [https://github.com/logicchains/LPATHBench/blob/master/writeup.md]? I posted this to the beginners group last week, but no reply, so trying again here. -- View this message in context: http://haskell.1045720.n5.nabble.com/Haskell-implementation-of-longest-path-... Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

Well... I don't think anyone would consider this horrendous thing,
idiomatic haskell...
2015-02-22 10:34 GMT+01:00 Jeremy
Compared to the Nim code [https://github.com/logicchains/LPATHBench/blob/master/nim.nim] for a longest path algorithm, Haskell [https://github.com/logicchains/LPATHBench/blob/master/hs.hs] looks horrendously verbose and ugly, even if you ignore the pragmas and imports.
Is this idiomatic Haskell style? Could it be clearer, but has to be written that way for performance - although it still takes 3.7x as long as the Nim version [https://github.com/logicchains/LPATHBench/blob/master/writeup.md ]?
I posted this to the beginners group last week, but no reply, so trying again here.
-- View this message in context: http://haskell.1045720.n5.nabble.com/Haskell-implementation-of-longest-path-... Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

On Sun, 22 Feb 2015 10:34:23 +0100, Jeremy
Compared to the Nim code [https://github.com/logicchains/LPATHBench/blob/master/nim.nim] for a longest path algorithm, Haskell [https://github.com/logicchains/LPATHBench/blob/master/hs.hs] looks horrendously verbose and ugly, even if you ignore the pragmas and imports.
Is this idiomatic Haskell style? Could it be clearer, but has to be written that way for performance - although it still takes 3.7x as long as the Nim version
You can replace case isVisited of True -> return () False -> do with unless isVisited $ do in several places. ("unless" is from Control.Monad) Other options for simplification: 76 if dist > maxVal then writeIORef max dist else return ()) -> 76 when (dist > maxVal) $ writeIORef max dist ("when" is also from Control.Monad) if dist > maxDist then dist else maxDist -> max dist maxDist in several places. Note, the you cannot use the function max, if you used max as a variable name, like in max <- GV.foldM' acc (0::Int32) (nodes V.! (fromIntegral nodeID)) (If you use -Wall when compiling, you probably get a warning when you use max as a variable name) Replace: newMax <- case isVisited of True -> return maxDist False -> do -> newMax <- if isVisited then return maxDist else do You used fromIntegral quite a lot, could you change some type(s) to prevent this? Regards, Henk-Jan van Tuyl -- Folding@home What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. http://folding.stanford.edu/ http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming --

Compared to the Nim code [https://github.com/logicchains/LPATHBench/blob/master/nim.nim] for a longest path algorithm, Haskell [https://github.com/logicchains/LPATHBench/blob/master/hs.hs] looks horrendously verbose and ugly, even if you ignore the pragmas and imports.
Is this idiomatic Haskell style? Could it be clearer, but has to be written that way for performance - although it still takes 3.7x as long as the Nim version [https://github.com/logicchains/LPATHBench/blob/master/writeup.md ]?
A clearer version http://lpaste.net/120981
On Sun, Feb 22, 2015 at 3:04 PM, Jeremy

On Sun, Feb 22, 2015 at 11:36 PM, Jyotirmoy Bhattacharya < jyotirmoy@jyotirmoy.net> wrote:
On Sun, Feb 22, 2015 at 3:04 PM, Jeremy
wrote: Compared to the Nim code [https://github.com/logicchains/LPATHBench/blob/master/nim.nim] for a longest path algorithm, Haskell [https://github.com/logicchains/LPATHBench/blob/master/hs.hs] looks horrendously verbose and ugly, even if you ignore the pragmas and imports.
Is this idiomatic Haskell style? Could it be clearer, but has to be written that way for performance - although it still takes 3.7x as long as the Nim version [https://github.com/logicchains/LPATHBench/blob/master/writeup.md ]?
A clearer version http://lpaste.net/120981 though this is 2x-3x slower than the Haskell version above.
Another version that uses mutable vectors to track the visited nodes and has almost the same run time as the Haskell version in the LPATHBench repository:
http://lpaste.net/121012 Regards, Jyotirmoy Bhattacharya
participants (4)
-
Atze van der Ploeg
-
Henk-Jan van Tuyl
-
Jeremy
-
Jyotirmoy Bhattacharya