-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Compactable #55
base: master
Are you sure you want to change the base?
Add Compactable #55
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wooo!!! Had a quick question about naming.
Compactable/apMaybe
Outdated
@@ -0,0 +1,10 @@ | |||
let Applicative = ./../Applicative/Type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this (and the other similar expressions) be suffixed with Optional
instead of Maybe
: i.e. apOptional
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are completely right. Was looking at the Haskell stuff 🙈
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great. I don’t have much opinion on the repetition stuff at the moment. But I think you need to merge in master to grab the circle config and get a green build.
@sellout I don't think that's the CI issue.
Looks like we don't have credits for this? |
Compactable/Type
Outdated
in λ(f : Type → Type) | ||
→ { mapOptional : | ||
∀(a : Type) → ∀(b : Type) → (a → Optional b) → f a → f b | ||
, mapEither : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the motivation behind removing mapEither
? If it's about having one function to implement, we can derive mapOptional
from mapEither
, but we cannot derive mapEither
from mapOptional
. In that sense, it seems better to keep mapEither
and have mapOptional
be a derived function. Is there a different reason to remove mapEither
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wrong, you did derive mapEither
! Forget I said anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can derive mapEither
from mapOptional
it's here :) The motivation was that mapOptional
is the canonical function when thinking about this class in terms of categories: Compactable f === KleisliFunctor Optional f
where kmap :: (a -> m b) -> f a -> f b
is specialised to (a -> Optional b) -> f a -> f b
i.e. mapOptional
🎉!
This will make future integration with catewaul
easier :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heh! I wrote my response before I saw the next comment 😄
Ah, well the previous failure was due to no CI config. This new one seems … wrong. This is an OSS project, I thought those wouldn’t require “credits”? |
Yeh I've no idea, should we ask ops? |
Compactable/separate
Outdated
@@ -0,0 +1,49 @@ | |||
{- | |||
|
|||
mapEither maps a function to Either over the `f` and `separate`s `Left`s from `Right`s. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This says mapEither
, but the file is separate
. I would change this comment to say something like “This expression maps …” to make it less likely to get out of sync.
Compactable/separate
Outdated
``` | ||
let E = constructors (./Either/Type Natural Natural) | ||
|
||
in ./Compactable/mapEither |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. Obviously harder to avoid the name. I guess we need like dhall-doctest now, right 😁
Either/compactable
Outdated
@@ -0,0 +1,31 @@ | |||
{- | |||
mapOptional : (a -> Optional b) -> Either m a -> Either m b |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t think this is useful documentation, especially since this is a type class instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching, I actually just put it there to help me implement it 😅
Either/flipEither
Outdated
|
||
in let E = constructors (Either Text Natural) | ||
|
||
in ./Either/flipEither Text Natural (E.Left "ohno") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably just rename this to flip
. Also, it’s probably type-classable, like Bifunctor-ish?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've leave it for now though and just rename to flip
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, Either
isn't an instance. Need to keep looking :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compactable/Type
Outdated
{- | ||
|
||
Compactable serves as an abstraction over filtering and partitioning, using two functions | ||
compact and separate, respectively. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes it sound like the type class still has multiple methods. I would rewrite this to discuss mapOptional
instead, and then move the other comments to the respective expressions.
Compactable/apEither
Outdated
@@ -0,0 +1,30 @@ | |||
{- | |||
apEither maps an `f` of functions to Eithers over the `f a` and `separate`s `Left`s from `Right`s. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Get rid of apEither
in the comment here.
Compactable/apOptional
Outdated
@@ -0,0 +1,31 @@ | |||
{- | |||
|
|||
apOptional maps a `f` of functions to Optionals over the `f` and `compact`s away the `None` values. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Get rid of “apOptional” here.
Compactable/bindEither
Outdated
@@ -0,0 +1,44 @@ | |||
{- | |||
|
|||
bindEither binds to a `f` of Optional over the `f a` and `separate`s `Left`s and `Right`s. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same, etc. for other files.
Compactable/compact
Outdated
@@ -0,0 +1,23 @@ | |||
{- | |||
|
|||
mapOptional maps a function to Optionals over the `f` and `compact`s away the `None` values. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This claims to be mapOptional, but isn’t.
Ah crap … apparently I left a ton of comments on an old commit sigh. |
I guess like two of my comments are still valid 🤷🏼♂️ |
Fixes #54 cc @joneshf
Notes:
map
,ap
,bind
,traverse
functions. @sellout you probably have some tricks here 😛