Skip to content

Add Compactable#55

Open
FintanH wants to merge 26 commits intoFormationAI:masterfrom
FintanH:fintan/compactable
Open

Add Compactable#55
FintanH wants to merge 26 commits intoFormationAI:masterfrom
FintanH:fintan/compactable

Conversation

@FintanH
Copy link
Copy Markdown
Contributor

@FintanH FintanH commented Feb 2, 2019

Fixes #54 cc @joneshf

  • Compactable typeclass
  • fromSeparate -- default compact
  • fromCompact -- defaults separate
  • Added combinators

Notes:

  • I should probably add documentation (definitely)
  • I feel like there's some very repetitive patterns happening in the map, ap, bind, traverse functions. @sellout you probably have some tricks here 😛

@FintanH FintanH added the Open Source Labelling open source contributions label Feb 2, 2019
@FintanH FintanH requested a review from sellout February 2, 2019 17:37
Copy link
Copy Markdown
Contributor

@joneshf joneshf left a 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.

Comment thread Compactable/apMaybe Outdated
@@ -0,0 +1,10 @@
let Applicative = ./../Applicative/Type
Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Contributor Author

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 🙈

Copy link
Copy Markdown
Contributor

@sellout sellout left a 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.

@FintanH
Copy link
Copy Markdown
Contributor Author

FintanH commented Feb 14, 2019

@sellout I don't think that's the CI issue.

# Blocked due to plan-no-credits-available Please purchase a new credit block then push a new commit or call the API to run a new build.

Looks like we don't have credits for this?

Comment thread Compactable/Type Outdated
in λ(f : Type → Type)
→ { mapOptional :
∀(a : Type) → ∀(b : Type) → (a → Optional b) → f a → f b
, mapEither :
Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor Author

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 :)

Copy link
Copy Markdown
Contributor Author

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 😄

@sellout
Copy link
Copy Markdown
Contributor

sellout commented Feb 14, 2019

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”?

@FintanH
Copy link
Copy Markdown
Contributor Author

FintanH commented Feb 14, 2019

Yeh I've no idea, should we ask ops?

Comment thread Compactable/separate Outdated
@@ -0,0 +1,49 @@
{-

mapEither maps a function to Either over the `f` and `separate`s `Left`s from `Right`s.
Copy link
Copy Markdown
Contributor

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.

Comment thread Compactable/separate Outdated
```
let E = constructors (./Either/Type Natural Natural)

in ./Compactable/mapEither
Copy link
Copy Markdown
Contributor

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 😁

Comment thread Either/compactable Outdated
@@ -0,0 +1,31 @@
{-
mapOptional : (a -> Optional b) -> Either m a -> Either m b
Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor Author

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 😅

Comment thread Either/flipEither

in let E = constructors (Either Text Natural)

in ./Either/flipEither Text Natural (E.Left "ohno")
Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
Contributor Author

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 :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Comment thread Compactable/Type Outdated
{-

Compactable serves as an abstraction over filtering and partitioning, using two functions
compact and separate, respectively.
Copy link
Copy Markdown
Contributor

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.

Comment thread 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.
Copy link
Copy Markdown
Contributor

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.

Comment thread 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.
Copy link
Copy Markdown
Contributor

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.

Comment thread 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.
Copy link
Copy Markdown
Contributor

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.

Comment thread Compactable/compact Outdated
@@ -0,0 +1,23 @@
{-

mapOptional maps a function to Optionals over the `f` and `compact`s away the `None` values.
Copy link
Copy Markdown
Contributor

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.

@sellout
Copy link
Copy Markdown
Contributor

sellout commented Feb 16, 2019

Ah crap … apparently I left a ton of comments on an old commit sigh.

@sellout
Copy link
Copy Markdown
Contributor

sellout commented Feb 16, 2019

I guess like two of my comments are still valid 🤷🏼‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Open Source Labelling open source contributions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants