[Haskell-cafe] Parsec question

Roman Cheplyaka roma at ro-che.info
Wed Jul 24 16:49:24 CEST 2013


Think about this: if you always take only the first element, why do you
need lists at all?

Roman

* C K Kashyap <ckkashyap at gmail.com> [2013-07-24 19:56:29+0530]
> Dear Cafe,
> 
> I am trying to implement[1] parsec in go using the "Monadic Parser
> Combinators" paper [2] . I've been able to implement "plus" "bind" and
> "many"
> While doing the implementation - I looked at bind closely
> 
> bind :: Parser a -> (a -> Parser b) -> Parser b
> p `bind` f = \inp -> concat [f v inp' | (v,inp') <- p inp]
> 
> I wondered if the result needs the complete list - wouldn't just the first
> successful value suffice?
> Perhaps -
> p `bind` f = \inp -> take 1 $ concat [f v inp' | (v,inp') <- p inp]
> 
> Will this miss out matches?
> 
> 
> Regards,
> Kashyap
> 
> [1] https://github.com/ckkashyap/parsec/blob/master/parsec.go
> [2] Monadic Parser Combinators: Graham Hutton, Erik Meijer

> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe





More information about the Haskell-Cafe mailing list