Attoparsec parser question

Hello I have this kind ot type data PoniEntry a = PoniEntry { poniEntryHeader :: [Text] , poniEntryDetector :: (Maybe (Detector a)) -- ^ Detector Name , poniEntryPixelSize1 :: (Length Double) -- ^ pixels size 1 , poniEntryPixelSize2 :: (Length Double) -- ^ pixels size 1 , poniEntryDistance :: (Length Double) -- ^ pixels size 2 , poniEntryPoni1 :: (Length Double) -- ^ poni1 , poniEntryPoni2 :: (Length Double) -- ^ poni2 , poniEntryRot1 :: (Angle Double) -- ^ rot1 , poniEntryRot2 :: (Angle Double) -- ^ rot2 , poniEntryRot3 :: (Angle Double) -- ^ rot3 , poniEntrySpline :: (Maybe Text) -- ^ spline file , poniEntryWavelength :: WaveLength -- ^ wavelength } deriving (Show) type Poni a = [PoniEntry a] And I try to create a Parser for the Poni type lengthP :: Text -> Parser (Length Double) lengthP key = do value <-doubleP key pure $ value *~ meter detectorP ∷ ToPyFAI a ⇒ a → Parser a detectorP a = do _ ← "Detector: " *> string (toPyFAI a) <* endOfLine pure a poniEntryP ∷ Detector a ⇒ a → Parser (PoniEntry a) poniEntryP a = PoniEntry <$> headerP <*> optional (detectorP a) <*> lengthP "PixelSize1: " <*> lengthP "PixelSize2: " <*> lengthP "Distance: " <*> lengthP "Poni1: " <*> lengthP "Poni2: " <*> angleP "Rot1: " <*> angleP "Rot2: " <*> angleP "Rot3: " <*> optional ("SplineFile: " *> takeTill isEndOfLine <* endOfLine) <*> lengthP "Wavelength: " <?> "poniEntryP" poniP :: Detector a ⇒ a → Parser (Poni a) poniP a = some (poniEntryP a) But when I compile this I get this error message. src/Hkl/PyFAI/Poni.hs:(118,16)-(131,24): Couldn't match type `attoparsec-0.10.4.0:Data.Attoparsec.Internal.Types.Parser Text (PoniEntry a)' with `a -> Parser (PoniEntry a)' Expected type: a -> Parser (PoniEntry a) Actual type: Parser (PoniEntry a) In the expression: PoniEntry <$> headerP <*> optional (detectorP a) <*> lengthP "PixelSize1: " <*> lengthP "PixelSize2: " <*> lengthP "Distance: " <*> lengthP "Poni1: " <*> lengthP "Poni2: " <*> angleP "Rot1: " <*> angleP "Rot2: " <*> angleP "Rot3: " <*> optional ("SplineFile: " *> takeTill isEndOfLine <* endOfLine) <*> lengthP "Wavelength: " <?> "poniEntryP" In an equation for `poniEntryP': poniEntryP a = PoniEntry <$> headerP <*> optional (detectorP a) <*> lengthP "PixelSize1: " <*> lengthP "PixelSize2: " <*> lengthP "Distance: " <*> lengthP "Poni1: " <*> lengthP "Poni2: " <*> angleP "Rot1: " <*> angleP "Rot2: " <*> angleP "Rot3: " <*> optional ("SplineFile: " *> takeTill isEndOfLine <* endOfLine) <*> lengthP "Wavelength: " > "poniEntryP" src/Hkl/PyFAI/Poni.hs:134:11-29: Couldn't match type `[Parser (PoniEntry a)]' with `Parser (Poni a)' Expected type: a -> Parser (Poni a) Actual type: a -> [Parser (PoniEntry a)] In the return type of a call of `some' In the expression: some (poniEntryP a) In an equation for `poniP': poniP a = some (poniEntryP a) I must say, that I do not understand what is wrong with my code. The lengthP code is ok, so why the detectorP is wrong ? thanks for your help Frederic

On Wed, May 24, 2017 at 12:18:21PM +0000, PICCA Frederic-Emmanuel wrote:
Hello
Hello Frederic, maybe next time attach a simple .hs file which replicates the issue (with import modules, etc.), this way it is simpler to diagnose. Just by scanning the code, this raises a red flag:
detectorP ∷ ToPyFAI a ⇒ a → Parser a detectorP a = do _ ← "Detector: " *> string (toPyFAI a) <* endOfLine pure a
"Detector: " is a plain String, so i guess putting a `string` before it (or whatever is needed) should solve the issue. Does that solve the problem? -F

Hello Francesco
maybe next time attach a simple .hs file which replicates the issue (with import modules, etc.), this way it is simpler to diagnose.
I will considere this next time.
Just by scanning the code, this raises a red flag:
detectorP ∷ ToPyFAI a ⇒ a → Parser a detectorP a = do _ ← "Detector: " *> string (toPyFAI a) <* endOfLine pure a
"Detector: " is a plain String, so i guess putting a `string` before it (or whatever is needed) should solve the issue.
Does that solve the problem?
I solved my problem doing something else, but thanks for your help. thanks a lot Fred
participants (2)
-
Francesco Ariis
-
PICCA Frederic-Emmanuel