aboutsummaryrefslogtreecommitdiff
path: root/bin/draw.hs
diff options
context:
space:
mode:
authorJustin Bedo <cu@cua0.org>2023-01-30 08:48:16 +1100
committerJustin Bedo <cu@cua0.org>2023-01-30 08:49:38 +1100
commit075e020dca3a673110a505e7cf17a93671b9a1d2 (patch)
tree4e39769a9cd36ff94e6a1d42f3d87cef9da55a19 /bin/draw.hs
parent49a50c4fa6ad06741dd3fa411a03a08e6f9192ff (diff)
code formatting
Diffstat (limited to 'bin/draw.hs')
-rw-r--r--bin/draw.hs15
1 files changed, 8 insertions, 7 deletions
diff --git a/bin/draw.hs b/bin/draw.hs
index 4e19992..89658f6 100644
--- a/bin/draw.hs
+++ b/bin/draw.hs
@@ -1,18 +1,19 @@
{-# LANGUAGE ViewPatterns #-}
+
module Main where
-import Options.Applicative
+import Data.List
import Data.List.Split
import qualified Data.Map as M
-import Data.List
+import Options.Applicative
type Props = [[Double]]
+
type Nodes = [Int]
-- Command line args
data Options = Options
- {
- nthr :: Int,
+ { nthr :: Int,
propsPath :: FilePath,
clusterPath :: FilePath,
dotPath :: FilePath
@@ -25,10 +26,10 @@ data Tree = Tree [Double] Int [Tree]
children (Tree _ _ cs) = cs
addChild :: Tree -> Tree -> Tree
-(Tree a b cs) `addChild` child = Tree a b (child:cs)
+(Tree a b cs) `addChild` child = Tree a b (child : cs)
buildTree :: Props -> Nodes -> Tree
-buildTree (transpose -> ps) cl = merge n [Tree (ps !! i) (tab !! i) [] | i <- [0..n]]
+buildTree (transpose -> ps) cl = merge n [Tree (ps !! i) (tab !! i) [] | i <- [0 .. n]]
where
tab = tabulate cl
n = length tab - 1
@@ -38,7 +39,7 @@ buildTree (transpose -> ps) cl = merge n [Tree (ps !! i) (tab !! i) [] | i <- [0
merge 0 ts = head ts
merge i ts =
let j = parent i
- in merge (i-1) $ take j ts <> [(ts !! j) `addChild` (ts !! i)] <> drop (j+1) ts
+ in merge (i - 1) $ take j ts <> [(ts !! j) `addChild` (ts !! i)] <> drop (j + 1) ts
-- Prune a tree according to a node threshold
prune th = fix prune'