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

Function to apply to a Moveable argument? #406

Open
andreasabel opened this issue Apr 10, 2022 · 3 comments · May be fixed by #413
Open

Function to apply to a Moveable argument? #406

andreasabel opened this issue Apr 10, 2022 · 3 comments · May be fixed by #413

Comments

@andreasabel
Copy link
Contributor

I spent considerable time searching the base-linear library for a function that would allow me to use a unrestricted function as a linear one provided the domain is Moveable. Is there something like that?

If not, these could be sensible additions to the library:

applyMove :: Movable a => (a -> b) %1 -> a %1 -> b
applyMove f x = f `applyUr` move x

applyUr :: (a -> b) %1 -> Ur a %1 -> b
applyUr f (Ur a) = f a

Example use:

import Control.Functor.Linear
import Data.HashMap.Mutual.Linear

lookupSt :: String %1 -> State (HashMap String v) (Ur (Maybe v))
lookupSt k = state (lookup `applyMove` k)
  -- lookup :: String -> HashMap String v %1 -> ...

Bikeshedding of the names welcome!
Maybe there are suitable operators for these function reminiscent of $.

@aspiwack
Copy link
Member

aspiwack commented Apr 11, 2022

applyUr f is unur . Data.fmap f. But I don't believe that we wrote an equivalent to applyMove (though I guess it's unur . Data.map f . move; but it's starting to be too unwieldy to use without naming it).

It has nice symmetry with the unsafe toLinear functions that we already have. Maybe is should be a variant on $? The already exists$! to mean strict apply. Should we take a symbol to indicate the use of move?

@andreasabel
Copy link
Contributor Author

Maybe $^ is still free (https://hoogle.haskell.org/?hoogle=%24%5E) and indicates some (upwards) movement ^ in connection with application $.

@aspiwack
Copy link
Member

Ok. Let's go for ($^).

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 a pull request may close this issue.

2 participants