[Haskell-beginners] Attoparsec parser question
PICCA Frederic-Emmanuel
frederic-emmanuel.picca at synchrotron-soleil.fr
Wed May 24 12:18:21 UTC 2017
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
More information about the Beginners
mailing list