Skip to content

Conversation

@hdgarrood
Copy link
Contributor

The function previously performed by the IsOption type class, namely,
the ability to control how a value of a specific type is rendered into
an Options value, is now taken care of by the specific Option
itself. Option now also admits a Contravariant instance due to this.

The behaviour previously captured by the IsOption (Maybe a) instance
is now captured slightly differently. If you had previously
written this:

someOption := (value :: Maybe a)

you can get the old behaviour back (namely, the above expression
evaluating to an empty Options if value was Nothing) by changing
the code to this:

maybe mempty (someOption :=) (value :: Maybe a)

There is also a newly provided helper function which captures the above
pattern: massoc, or its alias (:=?):

someOption :=? (value :: Maybe a)

Most code should continue to work without modification, but note that
the above constitutes a breaking change (as, of course, does the removal
of IsOption and a few other related functions which are no longer
needed).

Bonuses:

  • Everything is now documented
  • There is no longer any use of the FFI

The function previously performed by the `IsOption` type class, namely,
the ability to control how a value of a specific type is rendered into
an `Options` value, is now taken care of by the specific `Option`
itself. `Option` now also admits a `Contravariant` instance due to this.

The behaviour previously captured by the `IsOption (Maybe a)` instance
is now captured slightly differently. If you had previously
written this:

    someOption := (value :: Maybe a)

you can get the old behaviour back (namely, the above expression
evaluating to an empty `Options` if `value` was `Nothing`) by changing
the code to this:

    maybe mempty (someOption :=) (value :: Maybe a)

There is also a newly provided helper function which captures the above
pattern: massoc, or its alias (:=?):

    someOption :=? (value :: Maybe a)

Most code should continue to work without modification, but note that
the above constitutes a breaking change (as, of course, does the removal
of `IsOption` and a few other related functions which are no longer
needed).

Bonuses:

* Everything is now documented
* There is no longer any use of the FFI
@ethul
Copy link
Collaborator

ethul commented Jan 22, 2016

Thanks for the PR. I will dig into the changes.

@paf31 Since we chatted about the typeclass-based implementation a while back, do you have any thoughts on these changes? Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

Why does the key need to be passed here? Surely the Option knows the key already.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, I'll see if I can change this to just value -> Options opt.

Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using Op from contravariant. Then you get some nice instances.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, this is kind of a perfect way to compose options, providing sets of options which can be set at once.

Copy link
Contributor

Choose a reason for hiding this comment

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

If we don't need it, I think we should get rid, since we buy the opportunity to represent multiple keys with one Option, which can be very useful when providing an idiomatic interface to things of type Either via tags, for example.

Copy link
Collaborator

Choose a reason for hiding this comment

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

key was added in 384219d. I really can't recall a specific reason for adding this. I am open to removing it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually, @garyb does adding key ring any bells for you by chance? I can't recall why I made that commit.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry! I didn't seem to get the notification on this. I don't really recall anything specifically to do with key, but it's been a while since I made use of -options so it's a little hard to remember.

I've been trying to think where I might have used it, other than tweaking things in gulp-purescript, I feel like there is somewhere I'm forgetting about where I wrote some stuff from scratch and needed some assistance to get it to do what I wanted, but I have no idea what it was now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Another option is to keep the one-key-to-one-Option relationship, keeping key, and to add the Op version as an alternative for more complex scenarios.

@paf31
Copy link
Contributor

paf31 commented Jan 22, 2016

Looks good to me. If there is a major bump happening, maybe it make sense to update for 0.8 now?

@ethul
Copy link
Collaborator

ethul commented Jan 22, 2016

Thanks @paf31. I was thinking to bump to 0.6

@ethul
Copy link
Collaborator

ethul commented Jan 26, 2016

Are we okay to merge here, or should we remove key?

@paf31
Copy link
Contributor

paf31 commented Jan 27, 2016

Ping @garyb

@paf31
Copy link
Contributor

paf31 commented Jan 29, 2016

@ethul What do you think about moving this library into core or contrib? I think it solves a really common problem, and we'll probably find ourselves wanting a standard solution for FFI libraries.

If we want to go the Op/Divisible way (which I think would be really powerful, and has the delightful Op/Option pun built-in), I'm happy to put a variant of this PR together this weekend.

@ethul
Copy link
Collaborator

ethul commented Jan 29, 2016

I am happy to move it to core or contrib, whichever you think is most
appropriate. And a PR for Op/Divisibility would be great!

On Friday, 29 January 2016, Phil Freeman [email protected] wrote:

@ethul https://github.com/ethul What do you think about moving this
library into core or contrib? I think it solves a really common problem,
and we'll probably find ourselves wanting a standard solution for FFI
libraries.

If we want to go the Op/Divisible way (which I think would be really
powerful, and has the delightful Op/Option pun built-in), I'm happy to
put a variant of this PR together this weekend.


Reply to this email directly or view it on GitHub
#12 (comment)
.

@ethul
Copy link
Collaborator

ethul commented Feb 2, 2016

Closing via #13

@ethul ethul closed this Feb 2, 2016
@hdgarrood hdgarrood deleted the non-classy branch February 2, 2016 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants