Proper Treatment 正當作法/ blog/ posts/ The pointed-set monad
標籤 Tags:
2008-12-03 18:02

Chatting with Andres Löh, I wondered: Is the following pointed-set monad useful, besides for analyzing focus in natural language (Rooth 1985, 1996)?

data Pointed a = Pointed a [a]
  deriving (Eq, Ord, Show, Read)

toList (Pointed x xs) = x:xs

instance Monad Pointed where
  return x = Pointed x []
  Pointed x xs >>= k = Pointed y (ys ++ (xs >>= toList.k))
    where Pointed y ys = k x

Here is an example of use:

*Main> Pointed 3 [4] >>= \x -> Pointed x [x*10,x*20]
Pointed 3 [30,60,4,40,80]

Ok, I know, I should put it on Hackage. Is there a corresponding monad transformer?


Rooth, Mats. 1985. Association with focus. Ph.D. thesis, Department of Linguistics, University of Massachusetts.

Rooth, Mats. 1996. Focus. In The handbook of contemporary semantic theory, ed. Shalom Lappin, 271–297. Oxford: Blackwell.