@@ -13,7 +13,6 @@ module Data.Universe.Helpers (
1313 univCons ,
1414 univUncons ,
1515 univFromList ,
16- diagonal ,
1716 (+++) ,
1817 (+*+) ,
1918 choices ,
@@ -47,7 +46,7 @@ instance Applicative Univ where
4746
4847instance Monad Univ where
4948 return = Univ . return
50- m >>= f = Univ $ getUniv m >>= getUniv . f
49+ m >>= f = diagonal $ fmap f m
5150
5251instance Alternative Univ where
5352 empty = mempty
@@ -97,8 +96,8 @@ interleave = Univ . concat . transpose . fmap getUniv
9796-- not exponentially so.
9897--
9998-- TODO: `join`, check use-cases
100- diagonal :: [ Univ a ] -> Univ a
101- diagonal = Univ . concat . diagonals . fmap getUniv
99+ diagonal :: Univ ( Univ a ) -> Univ a
100+ diagonal = Univ . concat . diagonals . fmap getUniv . getUniv
102101
103102-- | Like 'diagonal', but expose a tiny bit more (non-semantic) information:
104103-- if you lay out the input list in two dimensions, each list in the result
@@ -128,7 +127,7 @@ Univ xs +*+ Univ ys = Univ $ unfairProduct xs ys
128127
129128unfairProduct :: [a ] -> [b ] -> [(a ,b )]
130129unfairProduct [] _ = [] -- special case: don't want to construct an infinite list of empty lists to pass to diagonal
131- unfairProduct xs ys = getUniv $ diagonal [Univ [(x, y) | x <- xs] | y <- ys]
130+ unfairProduct xs ys = getUniv $ diagonal $ Univ [Univ [(x, y) | x <- xs] | y <- ys]
132131
133132-- | Slightly unfair n-way Cartesian product: given a finite number of
134133-- (possibly infinite) lists, produce a single list such that whenever @vi@ has
0 commit comments