I'm trying to use uu-parsinglib to operate on [Word8]
rather than [Char].
(I want to use uu-parsinglib for the error reporting.)
I need a parser that will fetch me the next Word8
in the sequence, whatever it is.
Once I have that, I can build more complex parsers.
But I'm having trouble figuring out how to write it.
The closest I've been able to get is:
{-# LANGUAGE FlexibleContexts #-}
module Main where
import Control.Applicative ((<|>))
import Data.Word
import Text.ParserCombinators.UU.BasicInstances
pRawWord8 :: Parser Word8
pRawWord8 = pSatisfy (const True) (Insertion undefined undefined undefined)
However, that implementation apparently returns the wrong type.
amy2.hs:10:13:
Couldn't match type ‘Char’ with ‘Word8’
Expected type: Text.ParserCombinators.UU.Core.P
(Str Char state loc) Word8
Actual type: Text.ParserCombinators.UU.Core.P
(Str Char state loc) Char
In the expression:
pSatisfy (const True) (Insertion undefined undefined undefined)
In an equation for ‘pRawWord8’:
pRawWord8
= pSatisfy (const True) (Insertion undefined undefined undefined)
This surprises me, because I don't see how the type signature for pSatisfy
is restricting me to returning a Char
instead of a Word8
.
How can I implement pRawWord8
?
pSatisfy has type:
So the Parser returns the same type as the input (
a
). Since Parser isThe input to Parser is a ListLike of Char, and hence pSatisfy can only return a Parser Char. So the types do forbid what you're trying to do.
Maybe you should type your function as something like
Or define your own type synonym along these lines.