Skip to content

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.
@rfourquet rfourquet merged commit 2bb283f into master Sep 10, 2020
@rfourquet rfourquet deleted the pair-api branch September 10, 2020 08:24
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.

3 participants