Skip to content

instances for First and Last #17

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

Closed
wants to merge 3 commits into from

Conversation

matthewleon
Copy link
Contributor

Prompted by a discussion about strict instances that would work with iterate: #16

The First instance should fit that bill. Given that Maybe is in the deps, it feels like it belongs here.

@JordanMartinez
Copy link
Contributor

I'm not sure what the definition was for Unfoldable previously and if it changed at all between then and now. However, I don't think these instances as is will work. Consider the following instance:

instance unfoldableFirst :: Unfoldable First where
  unfoldr :: forall a b. (b -> Maybe (Tuple a b)) -> b -> First a
  unfoldr step x = First (maybe Nothing (Just <<< fst) (step x))

If we write (unfoldr (const Nothing) 1) :: First String, the value returned would be First Nothing :: First (Maybe String). The compiler correctly catches this unification issue with a compiler error.

We could get around this limitation if a had a Monoid instance. However, Unfoldable as it's currently defined does not provide a slot to require that anywhere (e.g. instance (Monoid a) => Unfoldable (First a) would no longer match the required kind signature despite being a valid instance otherwise).

So, I'm going to close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants