Skip to content
This repository has been archived by the owner on Feb 2, 2021. It is now read-only.

Add Foldable instance for Day #7

Closed
wants to merge 1 commit into from
Closed

Add Foldable instance for Day #7

wants to merge 1 commit into from

Conversation

LiamGoodacre
Copy link
Contributor

Also added tupleDay (<⊗>), for example:

eg0 :: Array String
eg1 :: Maybe String
eg2 :: Map Int String

eg3 = (eg0 <⊗> eg1 <⊗> eg2) # foldMap
  \(v0 /\ v1 /\ v2) -> v0 <> v1 <> v2

Wasn't sure what to call the function and it's operator, feel free to rename.

@@ -117,3 +124,9 @@ instance comonadDay :: (Comonad f, Comonad g) => Comonad (Day f g) where

instance comonadTrans :: Comonad f => ComonadTrans (Day f) where
lower = runDay \get fx gy -> get (extract fx) <$> gy

instance foldableDay :: (Foldable f, Foldable g) => Foldable (Day f g) where
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like an unusual choice of instance to me. That length (day _ fx gy) is length fx * length gy seems a bit strange. I know Foldable has no laws to satisfy, but still. I noticed this instance also isn't present in kan-extensions, so I'd be interested to hear if there's a reason why.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My only real motivation for this was that it felt like it should have one, similar to how the Coyoneda instance works:

toList (coyoneda t f) ≅ t <$> toList f
toList (day t f g) ≅ t <$> toList f <*> toList g

I'd also be interested to hear both: why it's not present in kan-extensions; and which alternative instances are possible.

@@ -94,6 +96,11 @@ assoclDay = runDay \phi f x -> runDay (\psi g h -> day identity (day (\a b c ->
assocrDay :: forall f g h. (f ⊗ g) ⊗ h ~> f ⊗ (g ⊗ h)
assocrDay = runDay \phi x h -> runDay (\psi f g -> day (#) f (day (\a b c -> phi (psi c a) b) g h)) x

tupleDay :: forall f g x y . f x -> g y -> Day f g (Tuple x y)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this maybe crosses the Fairbairn threshold. I'm curious what you use it for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was mainly to facilitate the above example. Will happily delete!

@LiamGoodacre
Copy link
Contributor Author

Thanks for your feedback @paf31

@LiamGoodacre LiamGoodacre closed this by deleting the head repository Jul 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants