0

[Word8][Char] ではなく、uu-parsinglib を使用して操作しようとしています。(エラー報告に uu-parsinglib を使用したい。)Word8それが何であれ、シーケンスの次のものを取得するパーサーが必要です。それができたら、より複雑なパーサーを作成できます。でも、書き方が分からなくて困っています。私が得ることができた最も近いものは次のとおりです。

{-# 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)

ただし、その実装は明らかに間違った型を返します。

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)

の型シグネチャがどのように aではなくpSatisfya を返すように制限しているのかわからないので、これは私を驚かせます。CharWord8

どうすれば実装できpRawWord8ますか?

4

1 に答える 1

1

pSatisfy には次のタイプがあります。

pSatisfy :: forall loc state a. (Show a, loc `IsLocationUpdatedBy` a, ListLike state a) => (a -> Bool) -> Insertion a -> P (Str a state loc) a

したがって、パーサーは入力 ( ) と同じ型を返しますa。パーサーは

type Parser a = (IsLocationUpdatedBy loc Char, ListLike state Char) => P (Str Char state loc) a

Parser への入力は Char の ListLike であるため、pSatisfy は Parser Char のみを返すことができます。したがって、型はあなたがやろうとしていることを禁止します。

たぶん、関数を次のように入力する必要があります

pRawWord8 :: (IsLocationUpdatedBy loc Word8, ListLike state Word8) => P (Str Word8 state loc) Word8

または、これらの線に沿って独自の型シノニムを定義します。

于 2015-07-21T16:17:52.930 に答える