Skip to content
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

sequence in haskell #319

Closed
metric-space opened this issue Jan 6, 2017 · 6 comments
Closed

sequence in haskell #319

metric-space opened this issue Jan 6, 2017 · 6 comments

Comments

@metric-space
Copy link

metric-space commented Jan 6, 2017

the type signature of sequence in Haskell is

sequence :: (Monad m, Traversable t) => t (m a) -> m (t a)

so I could have sequence [Left 4, Right 5] => Left 4

and sequence [Right 6, Right 9] => Right [6,9]

Is there an equivalent in sanctuary? I've been scanning libraries that implement the fantasy-land spec, none of them seem to have this (so far)

Edit : I understand it can be implemented as such (atleast for my task at hand)
x => S.reduce(S.lift2(S.C(S.append)),S.Right([]),x), was wondering why something as such is missing

@davidchambers
Copy link
Member

v0.11.1 provides:

v0.12.0 will provide fantasy-land/traverse methods instead (for compatibility with version 2 of the Fantasy Land spec) and polymorphic traverse and sequence functions which wrap Z.traverse and Z.sequence respectively.

Does this answer your question, @functor-soup?

@safareli
Copy link
Member

safareli commented Jan 7, 2017

so I could have sequence [Left 4, Right 5] => Left 4

I think you would get Left [4]

@joneshf
Copy link
Member

joneshf commented Jan 8, 2017

λ: :t sequenceA [Left 4, Right 5]
sequenceA [Left 4, Right 5] :: (Num a1, Num a) => Either a1 [a]

@metric-space
Copy link
Author

@davidchambers Hmm I do remember looking at that for quite some time, thought it was something else. I see I am wrong. How would you use const b = [S.Left(4), S.Right(5)] to get Left(4) using sanctuary'ssequence?

@safareli I believe @joneshf's comment clarifies that the answer would be Left 4 because the type signature highlights that pretty clearly

@safareli
Copy link
Member

safareli commented Jan 8, 2017

@functor-soup correct

@davidchambers
Copy link
Member

Here are the Sanctuary equivalents of your Haskell expressions, @functor-soup, on the dc-fantasy-land branch:

> S.sequence
sequence :: (Applicative f, Traversable t) => TypeRep f -> t (f b) -> f (t b)

> S.sequence(S.Either, [S.Left(4), S.Right(5)])
Left(4)

> S.sequence(S.Either, [S.Right(6), S.Right(9)])
Right([6, 9])

I'll close this issue as I believe we've answered your question. :)

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

No branches or pull requests

4 participants