Has anyone defined an `ap`-like function `:: f (f a -> f b) -> f a -> f b` where `f = Pattern`?

I found myself reminded of inhabit while reading your latest example, and came up with the below which seems to do as expected though with less new code and more usage of existing Tidal functions:

(import Data.Functor (bimap))

replace x = inhabit $ bimap id pure <$> x

or this, if you don't want to have to put strings in the table:

replace x = inhabit $ bimap show pure <$> x

(Alternatively, one could copy the code of inhabit itself and (either or both):

  • Replace its String dependency with an Eq constraint
  • Fall back on id instead of silence

Or, if you're okay with writing String keys and writing pure with the values, you can just use inhabit directly and with a potential (though likely overkill) benefit of being able to pattern directly inside the table values themselves. A whole 'nother layer of meta. :wink:
)

together with this:

meta pf p = pf >>= ($ p)

I'm curious, though, as to whether or not these implementations cover the same requirements.