
17 Oct
2011
17 Oct
'11
11:18 a.m.
Hello, I came across the following code: ngrams'' :: Int -> [a] -> [[a]] ngrams'' n l = do t <- Data.List.tails l l <- [take n t] Control.Monad.guard (length l == n) return l and tried to use the ">>=" operator in order to figure out how Monads work. I came up with: test l = (Data.List.tails l) >>= (\t -> [take 2 t]) >>= (\l -> if (length l == 2) then [l] else []) Questions: 1. How can I use Control.Monad.guard directly in "test l" 2. Related issue: how can create a List monad so that I can input "l" argument of "test l" directly? TIA, Hugo F.