!WwW       !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~   Safe 456>HV ralSize of a tree.ral Direction in .ral is a product of two f-. This way we can form a perfect binary tree.ralA  is isomorphic to Identityb, but we reimplement it here to have domain specific type. The short constructor name is a bonus.   SafeSafe /456>HX0Tral8Non-empty random access list, underlying representation.FThe structure doesn't need to be hidden, as polymorphic recursion of s starting from  keeps the   values well-formed. ralNon-empty random access list.ralSingle element  .ral for non-empty rals.ral fromNonEmpty ('a' :| ['b'..'f'])fromNonEmpty ('a' :| "bcdef")/explicitShow (fromNonEmpty ('a' :| ['b'..'f']))e"NE (Cons0 (Cons1 (Nd (Lf 'a') (Lf 'b')) (Last (Nd (Nd (Lf 'c') (Lf 'd')) (Nd (Lf 'e') (Lf 'f'))))))"ral List index.$fromNonEmpty ('a' :| ['b'..'f']) ! 0'a'$fromNonEmpty ('a' :| ['b'..'f']) ! 5'f'$fromNonEmpty ('a' :| ['b'..'f']) ! 61*** Exception: array index out of range: NERAList...ralsafe list index.%fromNonEmpty ('a' :| ['b'..'f']) !? 0Just 'a'%fromNonEmpty ('a' :| ['b'..'f']) !? 5Just 'f'%fromNonEmpty ('a' :| ['b'..'f']) !? 6NothingralFirst value, head of the list.'head $ fromNonEmpty $ 'a' :| ['b'..'f']'a'ralLast value of the list(last $ fromNonEmpty $ 'a' :| ['b'..'f']'f'ral import Data.Semigroup (Min (..))9ifoldMap1 (\_ x -> Min x) $ fromNonEmpty $ 5 :| [3,1,2,4]Min {getMin = 1}?ifoldMap1 (\i x -> Min (i + x)) $ fromNonEmpty $ 5 :| [3,1,2,4]Min {getMin = 3}ral.map toUpper (fromNonEmpty ('a' :| ['b'..'f']))fromNonEmpty ('A' :| "BCDEF")ral+imap (,) (fromNonEmpty ('a' :| ['b'..'f']))CfromNonEmpty ((0,'a') :| [(1,'b'),(2,'c'),(3,'d'),(4,'e'),(5,'f')])"ralAdjust a value in the list.0adjust 3 toUpper $ fromNonEmpty $ 'a' :| "bcdef"fromNonEmpty ('a' :| "bcDef");If index is out of bounds, the list is returned unmodified.1adjust 10 toUpper $ fromNonEmpty $ 'a' :| "bcdef"fromNonEmpty ('a' :| "bcdef")3adjust (-1) toUpper $ fromNonEmpty $ 'a' :| "bcdef"fromNonEmpty ('a' :| "bcdef")ral8fromNonEmpty ('a' :| "bc") <> fromNonEmpty ('x' :| "yz")fromNonEmpty ('a' :| "bcxyz")ral-I.length $ fromNonEmpty $ 'x' :| ['a' .. 'z']27  !" Safe /456>HX? #ralRandom access list.(ralEmpty #.empty :: RAList Int fromList [])ralSingle element #.*ral* for non-empty rals.,ralfromList ['a' .. 'f']fromList "abcdef"$explicitShow $ fromList ['a' .. 'f']p"NonEmpty (NE (Cons0 (Cons1 (Nd (Lf 'a') (Lf 'b')) (Last (Nd (Nd (Lf 'c') (Lf 'd')) (Nd (Lf 'e') (Lf 'f')))))))".ralsafe list index.fromList ['a'..'f'] !? 0Just 'a'fromList ['a'..'f'] !? 5Just 'f'fromList ['a'..'f'] !? 6Nothing2ral!map toUpper (fromList ['a'..'f'])fromList "ABCDEF"3ral imap (,) $ fromList ['a' .. 'f']:fromList [(0,'a'),(1,'b'),(2,'c'),(3,'d'),(4,'e'),(5,'f')]5ralAdjust a value in the list.#adjust 3 toUpper $ fromList "bcdef"fromList "bcdEf";If index is out of bounds, the list is returned unmodified.$adjust 10 toUpper $ fromList "bcdef"fromList "bcdef"&adjust (-1) toUpper $ fromList "bcdef"fromList "bcdef"ral fromList "abc" <> fromList "xyz"fromList "abcxyz"ral"I.length $ fromList $ ['a' .. 'z']26#%$&'()*+,-./012345SafeC6ral$Tail of non-empty list can be empty.$tail $ fromNonEmpty $ 'a' :| "bcdef"fromList "bcdef"7ral&uncons $ fromNonEmpty $ 'a' :| "bcdef"('a',fromList "bcdef")  !"67  76" !SafeE8raluncons $ fromList []Nothinguncons $ fromList "abcdef"Just ('a',fromList "bcdef")#%$&'()*+,-./0123458#%$&'()*-.8/0+,15234None&'.12=?@ACHSVXV 9ral(Perfectly balanced binary tree of depth n, with 2 ^ n elements.<ral9$ of zero depth, with single element.singleton True Leaf True=ralConvert 9 to list.GtoList $ Node (Node (Leaf 'a') (Leaf 'b')) (Node (Leaf 'c') (Leaf 'd'))"abcd">ral Indexing.Fral,foldr (:) [] $ Node (Leaf True) (Leaf False) [True,False]Jral3foldl (flip (:)) [] $ Node (Leaf True) (Leaf False) [False,True]Lral-length (universe :: Tree N.Nat3 (Wrd N.Nat3))8Mral'map not $ Node (Leaf True) (Leaf False)Node (Leaf False) (Leaf True)Nral(imap (,) $ Node (Leaf True) (Leaf False))Node (Leaf (0b0,True)) (Leaf (0b1,False))SralZip two Vecs with a function.TralZip two 99s. with a function that also takes the elements' indices.UralRepeat a value.repeat 'x' :: Tree N.Nat2 Char>Node (Node (Leaf 'x') (Leaf 'x')) (Node (Leaf 'x') (Leaf 'x'))VralGet all Vec n  indices in 9 n.$universe :: Tree N.Nat2 (Wrd N.Nat2)BNode (Node (Leaf 0b00) (Leaf 0b01)) (Node (Leaf 0b10) (Leaf 0b11)) 9;:<=>?@ABCDEFGHIJKLMNOPQRSTUVWX 9;:<=>?@ABDCEFGHIJKLMNOPQRSTUVWXNone&'.12=>?@AHSUVX[lral7Non-empty random access list, undelying representation.pralNon-empty random access list.tralt for non-empty rals.vralv for non-empty rals.ralZip two ls with a function.ralZip two l#s with a function which also takes  index.Clmnopqrstuvwxyz{|}~Cpqlmnorstuvw}~xyz{|None&'.12=>?@AHSUVXfvK ral#Length indexed random access lists.ralCons an element in front of .+reifyList "xyz" (print . toList . cons 'a')"axyz"ral Variant of  which computes the   dictionary at the same time.ral!The first element of a non-empty . reifyNonEmpty ('x' :| "yz") head'x'ral The last element of a non-empty . reifyNonEmpty ('x' :| "yz") last'z'ralConvert a list [a] to  b a . Returns ! if lengths don't match.+fromList "foo" :: Maybe (RAVec B.Bin3 Char)KJust (NonEmpty (NE (Cons1 (Leaf 'f') (Last (Node (Leaf 'o') (Leaf 'o')))))),fromList "quux" :: Maybe (RAVec B.Bin3 Char)Nothing*fromList "xy" :: Maybe (RAVec B.Bin3 Char)Nothing"ralreifyList "foo" printDNonEmpty (NE (Cons1 (Leaf 'f') (Last (Node (Leaf 'o') (Leaf 'o')))))reifyList "xyzzy" toList"xyzzy"ral Indexing.8let ral :: RAVec B.Bin4 Char; Just ral = fromList "abcd"ral ! minBound'a'ral ! maxBound'd' ral ! pop top'b'ralZip two s with a function.ralZip two #s with a function which also takes # index.ralRepeat a value.repeat 'x' :: RAVec B.Bin5 CharpNonEmpty (NE (Cons1 (Leaf 'x') (Cons0 (Last (Node (Node (Leaf 'x') (Leaf 'x')) (Node (Leaf 'x') (Leaf 'x')))))))ral%universe :: RAVec B.Bin2 (Pos B.Bin2)5NonEmpty (NE (Cons0 (Last (Node (Leaf 0) (Leaf 1)))))-let u = universe :: RAVec B.Bin3 (Pos B.Bin3)u>NonEmpty (NE (Cons1 (Leaf 0) (Last (Node (Leaf 1) (Leaf 2))))))P.explicitShow $ u ! Pos (PosP (Here WE))"Pos (PosP (Here WE))".let u' = universe :: RAVec B.Bin5 (Pos B.Bin5)toList u' == sort (toList u')True!!$     !"#$%&'()*+, - . /   0   1 2   ! " % ( ) * ,3445 16789%#&:;$'<=!()>*?+@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_` a1bcdef6g9h%i#j&k:$'lmn;o(p)q>r*s?t+u@vAwBxCyDEz{|}~./0] 12d69%#&:;()>*?+@ABCDE ,?*$&'+;1 ral-0.1-JTmjv0EEeolLkpkpBgUcbPData.RAList.TreeData.RAList.NonEmpty Data.RAListData.RAVec.TreeData.RAVec.NonEmpty Data.RAVecData.RAList.Tree.InternalData.RAList.NonEmpty.InternalData.RAList.InternalDirLRNodeNdLeafLf NERAList'LastCons0Cons1NERAListNE explicitShowexplicitShowsPrec singletoncons toNonEmpty fromNonEmpty!!?headlastlengthnullfoldMap1 foldr1MapifoldMap ifoldMap1 ifoldr1Mapmapimap itraverse itraverse1adjustRAListEmptyNonEmptyemptytoListfromListtailunconsTreetabulateleftmost rightmostfoldMapfoldrifoldrfoldlifoldltraverse traverse1zipWithizipWithrepeatuniverse liftArbitrary liftShrink$fFunctionTree$fCoArbitraryTree$fArbitraryTree$fArbitrary1Tree $fApplyTree$fSemigroupTree$fRepresentableTree$fDistributiveTree$fApplicativeTree$fHashableTree $fNFDataTree$fTraversable1Tree$fFoldable1Tree$fTraversableTree$fFoldableTree $fFunctorTree $fShowTree $fOrdTree$fEqTreeNERAVec'NERAVec singleton'consTreewithCons withConsTree unsingletonhead'last'toList' toNonEmpty' reifyNonEmptyreifyNonEmpty'index' tabulate'foldMap' ifoldMap' foldMap1' ifoldMap1'foldr' foldr1Map' ifoldr1Map'ifoldr'map'imap' traverse' itraverse' traverse1' itraverse1'zipWith' izipWith'repeat' universe'liftArbitrary' liftShrink'$fFunctionNERAVec'$fCoArbitraryNERAVec'$fArbitrary1NERAVec'$fApplyNERAVec'$fMonoidNERAVec'$fSemigroupNERAVec'$fRepresentableNERAVec'$fDistributiveNERAVec'$fApplicativeNERAVec'$fHashableNERAVec'$fNFDataNERAVec'$fTraversable1NERAVec'$fFoldable1NERAVec'$fTraversableNERAVec'$fFoldableNERAVec'$fFunctorNERAVec' $fOrdNERAVec'$fFunctionNERAVec$fCoArbitraryNERAVec$fArbitraryNERAVec$fArbitrary1NERAVec$fApplyNERAVec$fMonoidNERAVec$fSemigroupNERAVec$fRepresentableNERAVec$fDistributiveNERAVec$fApplicativeNERAVec$fHashableNERAVec$fNFDataNERAVec$fTraversable1NERAVec$fFoldable1NERAVec$fTraversableNERAVec$fFoldableNERAVec$fFunctorNERAVec $fEqNERAVec $fOrdNERAVec $fShowNERAVec$fShowNERAVec' $fEqNERAVec'RAVec$fFunctionRAVec$fCoArbitraryRAVec$fArbitraryRAVec$fArbitrary1RAVec $fApplyRAVec $fMonoidRAVec$fSemigroupRAVec$fRepresentableRAVec$fDistributiveRAVec$fApplicativeRAVec$fHashableRAVec $fNFDataRAVec$fTraversable1RAVec$fFoldable1RAVec$fTraversableRAVec$fFoldableRAVec$fFunctorRAVec $fOrdRAVec $fShowRAVec $fEqRAVecSizeIsTree safeIndexOffset$fSemigroupNERAList$fFoldableNERAList$fSemigroupRAList$fFoldableRAListghc-prim GHC.TypesBoolbin-0.1-1VmEg7qlTVO1si1D9V7wECData.BinP.PosPPosP' Data.Type.BinSBinIbase GHC.MaybeNothing reifyList Data.Bin.PosPos