How is this different from the list monad without mzero/[]? - Ryan Ingram
Well, the pointed-set monad is different from the nonempty-set monad, but I guess the pointed-list monad is no different from the nonempty-list monad…
An alternative pointed list monad:
data Pointed a = Pointed { fore::a, back::[a] } deriving (Eq,Show)
instance Functor Pointed where
fmap f (Pointed a bs) = Pointed (f a) (map f bs)
instance Monad Pointed where
return a = Pointed a []
Pointed a bs >>= f = let u = f a in Pointed (fore u) (back u ++ map (fore . f) bs)
test = Pointed 3 [4] >>= \x -> Pointed x [x*10,x*20]
It’s sort of additive where the usual list is multiplicative. It can be used to search trees in which there is a ‘spine’ and you only want to consider leaves a distance of at most one from that spine - if you see what I mean. Like matching strings with up to one error.
– Dan Piponi