Jeżeli chcesz utworzyć wartość typu Lexer Char, to musisz użyć konstruktora P, bo Lexer Char to synonim dla Parser (Loc, String) Char, a wartości typu Parser a b tworzy się konstruktorem P, gdzie argumentem tego konstruktora jest funkcja, która parsuje input i zwraca listę wyników.
Skrajnie prosty przykład, lekser który parsuje dowolny znak:
data Loc = Loc String Int Int deriving Show
data Parser b a = P (b -> [(a, b)])
parse :: Parser b a -> b -> [(a, b)]
parse (P p) inp = p inp
type Lexer a = Parser (Loc, String) a
char :: Lexer Char
char = P $ \(Loc path row col, input) ->
case input of
ch:rest -> [(ch, (Loc path row (col + 1), rest))]
[] -> []
main :: IO ()
main = print $ parse char (Loc "main.cpp" 1 1, "abc")