简体   繁体   中英

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 ?

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

You are talking about Alternative as @Robin Zigmond said:

instance Alternative [] where
    empty = []
    (<|>) = (++)

And if you want to know, it is also a MonadPlus :

instance MonadPlus []

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM