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

Inverse functions #15

Closed
mschauer opened this issue Jan 21, 2015 · 4 comments
Closed

Inverse functions #15

mschauer opened this issue Jan 21, 2015 · 4 comments

Comments

@mschauer
Copy link

I am thinking since a while, that it would be nice and very julian to match general functional expressions if the inverse of the function is provided, for example

@match (a,b) g(x,(y,z))

would translate into

x, _yz = @inversefun(g, (typeof(a,b))(a,b)
y,z = _yz

where @inversefun can be extended.

@kmsquire
Copy link
Contributor

kmsquire commented Apr 5, 2015

@mschauer, thank you for noting this. I was pretty busy when you contributed this comment, and it fell off my radar--sorry for my slow response!

I think that the suggestion sounds reasonable. I'm not sure if or when I'll have a chance to look at this, but if you have time and want to explore contributing something like this to Match.jl, I'd be happy to consider it.

@TotalVerb
Copy link

Macros cannot be extended, but inversefun can easily be made a function instead of a macro. One potential problem is that functions can't be dispatched on. Here's a very inelegant possible solution:

immutable Inverse end

f(x) = x^2
f(::Inverse, x) = sqrt(x)

that is, using the inverse function as a method of the original. This probably has ambiguity problems, and it doesn't strike me as very Julian.

@nystrom
Copy link
Collaborator

nystrom commented Sep 27, 2023

This is very similar to #92.

@gafter
Copy link
Member

gafter commented Nov 12, 2024

Treating as a dup of #92, which is probably closer to how we would handle this.

@gafter gafter closed this as completed Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants