You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This issue follows on from #2065 and #2079 , and concerns design choices for join vs. _>>=_, but is/might only be specific to the Monad instance(s) for Vec:
-- Diagonaldiagonal : Vec (Vec A n) n → Vec A n
diagonal [] = []
diagonal (xs ∷ xss) = head xs ∷ diagonal (map tail xss)
moduleDiagonalBindwhereinfixl1 _>>=_
_>>=_ : Vec A n → (A → Vec B n) → Vec B n
xs >>= f = diagonal (map f xs)
join : Vec (Vec A n) n → Vec A n
join = _>>= id
The first observation is that since map id is the identity, the definition of join should/could simply be reduced, in place, to
join = diagonal
So, the question is/might be: why go to the trouble of giving it a generic definition (which #2079 at present deprecates in favour of a generic join defined now in Effect.Monad), when the already-defined, and more efficient one, would be 'better'?
The second is that DiagonalBind._>>=_ might (?) better be given a direct recursive definition
_>>=_ : Vec A n → (A → Vec B n) → Vec B n
[] >>= f = []
x ∷ xs >>= f = head (f x) ∷ (xs >>= tail ∘ f)
such that join being then defined generically as _>>= id would make sense... but now, mutatis mutandis, we could instead definediagonal as:
diagonal = _>>= id whereopenDiagonalBind
or, if the inlining of id is regarded as problematic, as:
Have now propagated the first idea through #2079.
The second seems to have some 'interesting' questions about optimisation, in terms of when the various tails of xss in diagonal xss, resp. xs >>= f might be computed, so I have left things as they are for now.
This issue follows on from #2065 and #2079 , and concerns design choices for
join
vs._>>=_
, but is/might only be specific to theMonad
instance(s) forVec
:The first observation is that since
map id
is the identity, the definition ofjoin
should/could simply be reduced, in place, tojoin = diagonal
So, the question is/might be: why go to the trouble of giving it a generic definition (which #2079 at present deprecates in favour of a generic
join
defined now inEffect.Monad
), when the already-defined, and more efficient one, would be 'better'?The second is that
DiagonalBind._>>=_
might (?) better be given a direct recursive definitionsuch that
join
being then defined generically as_>>= id
would make sense... but now, mutatis mutandis, we could instead definediagonal
as:or, if the inlining of
id
is regarded as problematic, as:Would any of these observations yield actual improvements, though?
The text was updated successfully, but these errors were encountered: