1 module M (M,runM,newInt,newAux,choice,abort,runMAll,track) where
3 type State = (Int,Int,[String])
5 data M a = M (State -> [(a,State)])
8 return a = M (\s -> [(a,s)])
9 M m >>= k = M (\s -> concatMap (\(a,s') -> case k a of M l -> l s') (m s))
11 runM :: M a -> Maybe (a, [String])
12 runM (M m) = case m (1,0,[]) of
14 ((a,(_,_,ls)):_) -> Just (a,reverse ls)
16 runMAll :: M a -> [(a, [String])]
17 runMAll (M m) = map (\(a,(_,_,ls)) -> (a,reverse ls)) (m (1,0,[]))
20 newInt = M (\(i,j,ls) -> [(i,(i+1,j,ls))])
23 newAux = M (\(i,j,ls) -> [(j,(i,j-1,ls))])
25 choice :: M a -> M a -> M a
26 choice (M m) (M l) = M (\s -> m s ++ l s)
31 track :: String -> M ()
32 track l = M (\(i,j,ls) -> [((),(i,j,l:ls))])