-
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
Parameter order of linear collections #147
Comments
And the Generally speaking, both orders make a lot of sense, depending on how you are going to use the arguments. Also, in the case of cons :: a -> Vector a -> Vector a
snoc :: Vector a -> a -> Vector a Personnally, I have one order, which I use whenever I write a library. It's obviously the right one. The problem is that it's not always the same… But, you know, obvious. More seriously, argument ordering really don't have a good unique solution. Maybe we could make an argument that, since linear types favour chaining quite a bit, having an argument order which makes chaining easy is a reasonable choice. Quite frankly, I've got a hard time making a decision on this one. I don't really have a feel for how the Haskell community, at large, feels about argument order (nor any community to be honest, there are reasons why people I work with tend to immediately recognise code that I wrote…). @mboes do you have some opinion on the subject? |
As with issues #164 and #165; we're extending the collections interface, and it makes the inconsistency quite a bit obvious. I'd prefer if we make a decision sooner rather than later. I'm happy with either orders (with a slight preference towards collection-last order), both will be much better than status-quo. |
I think it's fine to break with (relatively hard to characterize consistently) precedent if it's to establish a convention that makes chaining more convenient. If such a convention is, "if you're in the fortunate case where there is exactly one linear argument, make it the last one", then let's establish that and document it in the design file. The precedent seems to be that imperative interfaces write the target first whereas pure interfaces usually have it last. But linear types gives us a pure interface for doing imperative things (like writing to an array cell). But that begs the question, what do we do with I/O? We're still in a monad in that case. |
I've been thinking about this in the past few days, actually. I think that what we should do is: At least we want
|
Late to the discussion, but I agree with @aspiwack. |
Currently, most of our linear collections (
Array
,Vector.Mutable
andHashMap
) take the collection as a first argument. Here are some examples from linear base:This is also what
vector
library does.But there are also places where we do the opposite:
(Also, as expected, the functions we re-implemented from
base
also tend to take the collection as the last argument)I think, taking the collection as the last parameter has some benefits:
vec & write 0 'a' & write 1 'c'
)Makes it clear that "given an
Int
and ana
that we're linearly transforming an Array to another". The alternative:In my opinion does not read as well, the unrestricted arrow before the result gives me the wrong impression.
The disadvantages I can think of:
vector
library.No matter which order we choose, it would be good to stick to it across the codebase.
This issue is broken up from the original PR: #146
The text was updated successfully, but these errors were encountered: