Skip to content

Add S combinator i.e. ap for (->) a #455

Description

@infinity0

The S combinator is occasionally useful for writing stuff in point-free style, if you're defining a type alias over a composition of the standard defunctionalisation symbols instead of writing your own type family.

In regular Haskell this is <*> for the (->) a instance of Applicative. However, for what I assume are hard technical reasons, neither (->) a nor (~>) a are instances of PApplicative / SApplicative in singletons, or any of the other expected classes for that matter. Nevertheless, the function doesn't require these instances and can be defined straightforwardly by itself:

singletons [d|
  ap :: (x -> y -> z) -> (x -> y) -> (x -> z)
  ap f g x = f x (g x)
  |]

which when promoted is essentially

type instance Apply (Ap f g) a = Apply (Apply f a) (Apply g a)

plus its defunctionalisation symbols. However I'm not sure the best name for it, ap is of course taken already by Monad.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions