Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I call a monoid that also supports lifting?

What I mean is a device like a list:

mempty = [ ]
lift x = [x]
mappend = (++)

Is it merely IsList?

like image 298
Ignat Insarov Avatar asked Jan 22 '26 10:01

Ignat Insarov


1 Answers

Given the framing of your question, I would be inclined to characterise your lift...

(:[]) :: a -> [a]

... as reflecting how lists are an encoding of the free monoid for Haskell types. In particular, the universal property (illustrated by the diagram at the end of the Category Theory for Programmers chapter linked to above) implies that:

-- q is an arbitrary a -> m function, with m being an arbitrary monoid.
foldMap q . (:[]) = q

As far as the types go, Alternative might seem to also express what you are looking for: empty and (<|>) are generally expected to be monoidal operations, and pure from Applicative could be taken as your lift. However, I'm not sure if there is any connection that might be drawn between pure and the Alternative methods that would clarify the role of pure in such a construction. (On this latter point, you might find this tangentially related question which discusses the relationship between Alternative and Applicative interesting.)

like image 117
duplode Avatar answered Jan 24 '26 04:01

duplode



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!