module ArrayList exposing ( ArrayList, nil, isEmpty , cons, head, tail -- list-like operations , get, set -- array-like operations ) type alias Rank = Int type LeafTree a = Leaf a | Branch Rank (LeafTree a) (LeafTree a) type ArrayList a = ArrayList (List (LeafTree a)) ---------------------------------------------------------------------- nil : ArrayList a nil = ArrayList [] isEmpty : ArrayList a -> Bool isEmpty arrayList = arrayList == nil rank : LeafTree a -> Int rank t = case t of Leaf _ -> 0 Branch r _ _ -> r ---------------------------------------------------------------------- -- list-like operations cons : a -> ArrayList a -> ArrayList a cons x (ArrayList trees) = ArrayList (consTree (Leaf x) trees) consTree : LeafTree a -> List (LeafTree a) -> List (LeafTree a) consTree t1 trees = Debug.todo "consTree" splitTree : LeafTree a -> (a, List (LeafTree a)) splitTree t = Debug.todo "splitTree" head : ArrayList a -> Maybe a head (ArrayList trees) = case trees of [] -> Nothing t::rest -> let (x, ts) = splitTree t in Just x tail : ArrayList a -> Maybe (ArrayList a) tail (ArrayList trees) = case trees of [] -> Nothing t::rest -> let (x, ts) = splitTree t in Just (ArrayList (ts ++ rest)) ---------------------------------------------------------------------- -- array-like operations get : Int -> ArrayList a -> Maybe a get i (ArrayList trees) = Debug.todo "get" set : Int -> a -> ArrayList a -> Maybe (ArrayList a) set i a (ArrayList trees) = Debug.todo "set"