私は次のカスタムデータ型を持っている:カスタムデータ型とGADTの混乱?
data FirstPair' a b = FirstPair a b deriving (Show, Ord, Eq)
type FirstPair a = FirstPair' a a
data SecondPair' a b = SecondPair a b deriving (Show, Ord, Eq)
type SecondPair a = SecondPair' a a
私は私の機能のためにGADT構造を作成しようとしています:
data Generator a where
Success :: FirstPair a -> Generator (SecondPair a)
Fail :: FirstPair a -> Generator Bool
myFunction :: Generator a -> a
myFunction (Success fp) = SecondPair "21" "24"
myFunction (Fail fp) = False
「ジェネレーター」タイプの役割が力に私を有効にすることです'Success'が渡された場合は 'myPunction'のインスタンスを返し、 'Fail'が渡された場合は 'False'を返します。
しかし、私はこのエラーを取得しています:
"Could not deduce: a1 ~ [Char] from the context: a ~ SecondPair' a1 a1 bound by a pattern with constructor: Success :: forall a. FirstPair a -> Generator (SecondPair a)"
私はここで間違って何をしているのですか?
あなたの質問にいくつかのコードがないようです。あなたのエラーは 'ContextaPair''を参照していますが、あなたはそれを言及していません。実際のコードを投稿できますか? – crockeea
投稿したのと同じコードをまだ実行していません。あなたのコードには[Char]の値はありません。 – chepner