MFlamer
MFlamer

Reputation: 2450

Type confusion in simple function

I've been away from Haskell for quite a while. I'm working through "Implementing Functional Languages A Tutorial" now to get back up to speed and learn more about what goes on under the hood. I can't seem to get how the argument "tokens" fits in here. The type signature clearly says this function takes a function and 2 parsers and returns a parser. Is "tokens" the result of the list comprehension being used in the list comprehension? Thanks.

pThen :: (a -> b -> c) -> Parser a -> Parser b -> Parser c
pThen combine p1 p2 tokens =
    [(combine v1 v2, tokens2) | (v1, tokens1) <- p1 tokens,
                                (v2, tokens2) <- p2 tokens1]

Edit: After reading the helpful answer below, I noticed a little earlier in the book this simpler example. It's even more obvious here, just in case this is helpful to someone else in the future.

pAlt :: Parser a -> Parser a -> Parser a    

pAlt :: Parser a -> Parser a -> Parser a
pAlt p1 p2 toks = (p1 toks) ++ (p2 toks)

Upvotes: 3

Views: 69

Answers (1)

kosmikus
kosmikus

Reputation: 19637

Parser is itself a type synonym for a function type, and tokens is the argument of the resulting Parser.

Upvotes: 5

Related Questions