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

introduce a Pair API (alternative to make) #4

Merged
merged 3 commits into from
Sep 10, 2020
Merged

introduce a Pair API (alternative to make) #4

merged 3 commits into from
Sep 10, 2020

Conversation

rfourquet
Copy link
Member

This make the following API available:

  • rand(T => x) is equivalent to rand(make(T, x))
  • rand(T => (x, y, ...)) is equivalent to rand(make(T, x, y, ...))

@mschauer
Copy link

mschauer commented Jun 4, 2019

Wouldn't the order x=>T be more natural, as in x::T?

@rfourquet
Copy link
Member Author

rfourquet commented Jun 4, 2019

Ah interesting, didn't think about it. The T => x order reads for me as "generate a T, and here is/are the parameters to do it. It also match the order in make, and puts the emphasize on what type has to be built. But x => T reads as "from this/these values (arguments), construct a T.

@rfourquet
Copy link
Member Author

I will rebase and merge. I still prefer the T => x syntax. This can still be changed later if there is support. This will be considered experimental at this point, and library code should only use make (while the => syntax can be used in the REPL or throwaway scripts).

@rfourquet rfourquet force-pushed the pair-api branch 2 times, most recently from e4716c6 to 38beaf5 Compare September 9, 2020 17:51
@rfourquet
Copy link
Member Author

rfourquet commented Sep 9, 2020

Another small argument in favor of the T => x order is the right-associativity of =>. Indeed, x itself can be a Pair, but not T. So if x is a Pair S => y, then T => S => y is equal to T => (S => y) == T => x. E.g.:

julia> rand(NTuple{4} => Complex => 1:3)
(2 + 2im, 2 + 3im, 1 + 3im, 2 + 1im)

(this example does not work yet with this PR, patch coming).

Do not restrict the first argument to be a `DataType`/`UnionAll`, as
`make` is about to start accepting non-type objects as first argument.
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