-
Notifications
You must be signed in to change notification settings - Fork 37
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
Eq and Ord classes don't seem very useful #447
Comments
A couple examples:
|
I'm being silent on this issue, because I need to think about it. Apologies. |
Oooff… I kind of forgot about this issue for a while. Sorry. My intention with these is type is that
You come with two counter-example. Mutable arrays are not dupable, neither would mutable byte arrays. Nevertheless it may make sense to compare them.
There is more than one way to think about this.
Let me riff on this third possibility for a little while. We could say that, instead of cas :: a %1 -> a %1 -> (a, a) Where the guarantee is that in the returned pair, the smaller It's quite clear that a linear However, it's far from perfect. For instance, you can't write quicksort or mergesort with cas (exercise: try). Sorting that can be done with cas are called network sorts, the most famous is the bitonic sort. One key issue with Ok, maybe let's add a boolean: cas :: a %1 -> a %1 -> (Bool,a, a) It's not much worse, and it's easy to produce a version that doesn't return the boolean. It does encode the additional ordering structure in the ordering of the pair. Pretty neat. But I don't think it suffices for mergesort: at some point in merge sort you have cas :: a %1 -> a %1 -> (Ordering, a, a) This is your Well… I wrote a lot of words, not many are useful, are they? |
I could be wrong, but it seems to be that having
==
and (probably)compare
consume their arguments is wrong for the vast majority of types that need to be handled linearly. I would expect something more likeThe text was updated successfully, but these errors were encountered: