Created
July 11, 2018 12:45
-
-
Save ccapndave/5837f5f00172890b984243bbdf92b524 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Tree4 exposing (..) | |
import Array exposing (Array) | |
import Data exposing (Data) | |
type Tree4 a b c leaf = | |
Tree4 | |
{ data : Data a leaf | |
, children : Array (Tree3 b c leaf) | |
} | |
type Tree3 a b leaf = | |
Tree3 | |
{ data : Data a leaf | |
, children : Array (Tree2 b leaf) | |
} | |
type Tree2 a leaf = | |
Tree2 | |
{ data : Data a leaf | |
, children : Array leaf -- not sure about this; should I make a Tree1 anyway for consistency? | |
} | |
type TreePath4 a b c leaf = | |
TreePath4 | |
{ tree : Tree4 a b c leaf | |
, path : Array Int | |
} | |
type TreePath3 a b c leaf = | |
TreePath3 | |
{ tree : Tree4 a b c leaf | |
, path : Array Int | |
} | |
type TreePath2 a b c leaf = | |
TreePath2 | |
{ tree : Tree4 a b c leaf | |
, path : Array Int | |
} | |
type TreePath1 a b c leaf = | |
TreePath1 | |
{ tree : Tree4 a b c leaf | |
, path : Array Int | |
} | |
-- 4 | |
treeChildren4 : Tree4 a b c leaf -> Array (Tree3 b c leaf) | |
treeChildren4 (Tree4 { children }) = children | |
treeData4 : Tree4 a b c leaf -> Data a leaf | |
treeData4 (Tree4 { data }) = data | |
data4 : TreePath4 a b c leaf -> Data a leaf | |
data4 = getFocusedTree4 >> treeData4 | |
top4 : TreePath4 a b c leaf -> TreePath4 a b c leaf | |
top4 (TreePath4 { tree, path }) = TreePath4 { tree = tree, path = path } | |
offset4 : Int -> TreePath4 a b c leaf -> Maybe (TreePath4 a b c leaf) | |
offset4 dx treePath = Nothing -- top level can't have an offset (but I could use up and maybe to make them all the same) | |
down4 : Int -> TreePath4 a b c leaf -> Maybe (TreePath3 b c leaf) | |
down4 idx = Debug.crash "" | |
-- up4 : TreePath4 a b c leaf -> Never | |
-- up4 = ??? | |
-- 3 | |
treeChildren3 : Tree3 a b leaf -> Array (Tree2 b leaf) | |
treeChildren3 = Debug.crash "" | |
data3 : TreePath3 a b leaf -> Data a leaf | |
data3 = Debug.crash "" | |
top3 : TreePath3 a b leaf -> TreePath4 a b c leaf | |
top3 = Debug.crash "" | |
offset3 : Int -> TreePath3 a b leaf -> Maybe (TreePath3 a b leaf) | |
offset3 dx = Debug.crash "" | |
down3 : Int -> TreePath3 a b leaf -> Maybe (TreePath2 b leaf) | |
down3 idx = Debug.crash "" | |
-- 2 | |
children2 : Tree2 a b leaf -> Array leaf | |
children2 = Debug.crash "" | |
data2 : TreePath2 a leaf -> Data a leaf | |
data2 = Debug.crash "" | |
top2 : TreePath2 a leaf -> TreePath4 a b c leaf | |
top2 = Debug.crash "" | |
offset2 : Int -> TreePath2 a leaf -> Maybe (TreePath2 a leaf) | |
offset2 dx = Debug.crash "" | |
down2 : Int -> TreePath2 a leaf -> Maybe (TreePath1 leaf) | |
down2 idx = Debug.crash "" | |
-- 1 | |
data1 : TreePath1 leaf -> Data a leaf -- this could just be leaf I suppose but it might be inconsistent | |
data1 = Debug.crash "" | |
top1 : TreePath1 leaf -> TreePath4 a b c leaf | |
top1 = Debug.crash "" | |
offset1 : Int -> TreePath1 leaf -> Maybe (TreePath1 leaf) | |
offset1 dx = Debug.crash "" | |
--down1 : Int -> TreePath2 a leaf -> Maybe (TreePath1 leaf) | |
--down1 idx = Debug.crash "" | |
getFocusedTree4 : TreePath4 a b c leaf -> Tree4 a b c leaf | |
getFocusedTree4 (TreePath4 { tree, path }) = | |
tree | |
getFocusedTree3 : TreePath3 a b c leaf -> Tree3 b c leaf | |
getFocusedTree3 (TreePath3 { tree, path }) = | |
tree | |
|> treeChildren4 | |
|> Array.get (Array.get 0 path |> unsafe "getFocusedTree3") | |
|> unsafe "getFocusedTree3" | |
getFocusedTree2 : TreePath2 a b c leaf -> Tree2 c leaf | |
getFocusedTree2 (TreePath2 { tree, path }) = | |
getFocusedTree3 (TreePath3 { tree = tree, path = path }) | |
|> treeChildren3 | |
|> Array.get (Array.get 1 path |> unsafe "getFocusedTree2") | |
|> unsafe "getFocusedTree2" | |
-- getFocusedTree1 : TreePath1 a b c leaf -> leaf | |
-- getFocusedTree1 (TreePath2 { tree, path }) = | |
-- getFocusedTree3 (TreePath3 { tree = tree, path = path }) | |
-- |> children3 | |
-- |> Array.get (Array.get 1 path |> unsafe "getFocusedTree2") | |
-- |> unsafe "getFocusedTree2" | |
unsafe : String -> Maybe a -> a | |
unsafe msg maybe = | |
case maybe of | |
Just a -> a | |
Nothing -> Debug.crash msg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment