-
Notifications
You must be signed in to change notification settings - Fork 170
Add anonymous functions to Q# #181
Comments
Yes, that's definitively on our roadmap. There are a couple of immediate things we need to prioritize, but this is by far the most requested language feature currently. Thanks for filing it! |
Interested? Absolutely :)! Though I will sure need some guidance first. I've noticed that the Q# compiler is written in F# - I should be able to handle that. But I'd appreciate any hints about where to start. |
Awesome!
For language features we will want a proper spec before they are officially included in a release (i.e. merged back to master). We have a pretty good idea on how the feature should look like, but haven't gotten around to writing down the corresponding proposal. I'm happy to work with you to produce that, or I am also happy to take care of that if you prefer. To get an idea of what questions we consider for language features I'll post an empty outline/template below. If you would like to focus on contributing to the implementation instead I suggest I walk you through it as we go. A good place to get started is the parser. @wsgac Does that sound like a good start or would you like to be involved in formulating the proposal? |
And here is roughly the outline that we follow for new language features: ProposalTODO: JustificationTODO: DescriptionTODO: Current StatusTODO: ExamplesExample 1: // TODO:
// Insert code example that illustrates what is described above.
// Comment your code to further elaborate and clarify the example.
TODO: Proposed ModificationTODO: ExamplesExample 1: // TODO:
// Insert code example that illustrates what is described above.
// Comment your code to further elaborate and clarify the example.
TODO: ImplementationTODO: TimelineTODO: Further ConsiderationsTODO: Related MechanismsTODO: Impact on Existing MechanismsTODO: Anticipated Interactions with Future ModificationsTODO: AlternativesTODO: Comparison to AlternativesTODO: Raised ConcernsAny concerns about the proposed modification will be listed here and can be addressed in the Response section below. Response |
I could imagine working on this. Would it be sensible to just transform an anonymous function
into
where z is a placeholder for some number of variables (the types of which I could find in a context)? On a related note, I've been unable to find a formal language spec for Q#. Is it based on some Hindley-Milner style type system or something c#-like hand-rolled? |
@anfelor |
@bettinaheim Unfortunately, the new semester started in Germany this week and so I might not have a lot of time anymore. Still, I could try to make some progress as time allows. |
@anfelor @wsgac |
It is frequently convenient to express functional concepts using one-off functions or operations. For simple cases, such as an existing operation with certain arguments fixed, partial operation with
_
is sufficient. However, sometimes one wishes to express more complex computation, hence the need for anonymous functions (lambdas).To keep the overhead to a minimum, it should probably follow the existing
C#
syntax for lambdas, i.e.(arguments) => (body)
. So, an example use could be something like:q => CNOT(qs[0], q)
.The text was updated successfully, but these errors were encountered: