What I mean is a device like a list:
mempty = [ ]
lift x = [x]
mappend = (++)
Is it merely IsList
?
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 []