Skip to content

Function to apply to a Moveable argument? #406

Description

@andreasabel

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 $.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions