Emily
Emily

Reputation: 2684

A name for a product of `Const` and a functor?

Is SF already defined anywhere, or does it at least have a name?

data SF a f x = SF a (f x)

instance Functor f => Functor (SF a f) where
  fmap g (SF a fx) = SF a (fmap g fx)

Upvotes: 6

Views: 1173

Answers (2)

J. Abrahamson
J. Abrahamson

Reputation: 74334

You could just define functor products

data (f :* g) a = P (f a) (g a) deriving Functor

and then write it directly

type SF a f = Const a :* f

Upvotes: 1

chi
chi

Reputation: 116139

Your functor looks like

type SF a f = (,) a :. f

using functor-combo notation.

(I somehow prefer to look at it using composition, rather than using product and Const.)

Upvotes: 4

Related Questions