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

Ord compare #49

Closed
goodmind opened this issue Apr 11, 2018 · 10 comments
Closed

Ord compare #49

goodmind opened this issue Apr 11, 2018 · 10 comments

Comments

@goodmind
Copy link

goodmind commented Apr 11, 2018

what about Ord's compare function?

type Ordering = -1 | 0 | 1
interface Ord<A> extends Setoid<A> {
  compare(a: A, b: A): Ordering
}

In Haskell's hackage about Data.Ord

Minimal complete definition: either compare or <=. Using compare can be more efficient for complex types.

@davidchambers
Copy link
Member

We can have sort without the -1/0/1 ugliness required by Array#sort. ;)

@goodmind
Copy link
Author

goodmind commented Apr 11, 2018

@davidchambers but you can derive compare from lte

@davidchambers
Copy link
Member

What's the advantage of compare over lte?

@rpominov
Copy link
Member

I think most of the discussion about this happened at fantasyland/fantasy-land#235 . And seems like the summary as David pointed out is that boolean is better as return type than number.

Also, we try to avoid breaking changes as much as possible, so this change is unlikely to happen, and I'm going to close this issue for now.

@goodmind
Copy link
Author

Sanctuary also doesn't seem to support static-land

@davidchambers
Copy link
Member

Sanctuary also doesn't seem to support static-land

I'm not intimately familiar with Static Land, so please correct me if I am wrong, but my understanding is that the Sanctuary module is a polymorphic Static Land module.

We can create values of type Maybe a or Either a b by using the of function of the S module:

> S.of (S.Maybe) (64)
Just (64)

> S.of (S.Either) (64)
Right (64)

We can interact with these values by using the map function of the S module:

> S.map (Math.sqrt) (S.of (S.Maybe) (64))
Just (8)

> S.map (Math.sqrt) (S.of (S.Either) (64))
Right (8)

If this does not count as Static Land support, I'd love to know what more Sanctuary could provide.

@goodmind
Copy link
Author

@davidchambers if I have static land Ord module, how do I use sanctuary sort?

@davidchambers
Copy link
Member

Good question, @goodmind! I see the problem now. @rpominov, perhaps you could help with this. How would one change sort :: (Ord a, Applicative m, Foldable m, Monoid (m a)) => m a -> m a to work with Static Land? Must it take TypeRep m and TypeRep a as additional arguments?

-S.sort (['foo', 'bar', 'baz'])
+S.sort (Array) (String) (['foo', 'bar', 'baz'])

@rpominov
Copy link
Member

rpominov commented Apr 13, 2018

Right, since #45 isn't resolved yet, the only way to implement sort is to pass modules/TypeReps for both types explicitly.

@davidchambers
Copy link
Member

Thanks, Roman. #45 will be terrific, in that case. :D

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

3 participants