linear-base
linear-base copied to clipboard
Function to apply to a `Moveable` argument?
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 $.
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?
Maybe $^ is still free (https://hoogle.haskell.org/?hoogle=%24%5E) and indicates some (upwards) movement ^ in connection with application $.
Ok. Let's go for ($^).