Could you show such a different implementation for either list or maybe?
newtype HeadList a = HeadList { getHeadList :: [a] } instance Monad HeadList where return a = HeadList [a] m >>= f = HeadList $ fmap (head . getHeadList . f) (getHeadList m)
But you could imagine putting any function that returns one result. min max avg normalize, etc
-- const [] for a HeadList quux :: a -> HeadList a quux = HeadList . (const []) *Main> HeadList "hello... no wait" >>= quux HeadList {getHeadList = "*** Exception: Prelude.head: empty list
But you could imagine putting any function that returns one result. min max avg normalize, etc