私は一緒に次のクラスDomain
とそのインスタンスTrivialDomain
タイプ曖昧
{-# LANGUAGE TypeFamilies #-}
data Transition = Transition
class Domain d where
type Set d
type Engine d :: * -> *
top :: Engine d (Set d)
-- ...
complement :: Set d -> Engine d (Set d)
exclude :: Set d -> Set d -> Engine d (Set d)
-- ...
data TrivialDomain = TrivialDomain
instance Domain TrivialDomain where
type Set TrivialDomain = [Int]
type Engine TrivialDomain = IO
top = return [0..10]
-- ...
complement a = top >>= (flip exclude) a
exclude a b = return $ filter (not . (`elem` b)) a
-- ...
を入れしようとしていますが、私は、私は私が
test3.hs:25:21:
Couldn't match type ‘Engine d0’ with ‘IO’
The type variable ‘d0’ is ambiguous
Expected type: IO (Set d0)
Actual type: Engine d0 (Set d0)
In the first argument of ‘(>>=)’, namely ‘top’
In the expression: top >>= (flip exclude) a
test3.hs:25:35:
Couldn't match type ‘Set d1’ with ‘[Int]’
The type variable ‘d1’ is ambiguous
Expected type: Set d0 -> [Int] -> IO [Int]
Actual type: Set d1 -> Set d1 -> Engine d1 (Set d1)
In the first argument of ‘flip’, namely ‘exclude’
In the second argument of ‘(>>=)’, namely ‘(flip exclude) a’
を理解するために失敗し、次のエラーが発生します取得しておきますインスタンスの宣言でEngine d (Set d)
がIO [Int]
に解決されると予想されますが、そうではありません。少なくともGHCはそうは思わない。私は何が欠けていますか?
を、あなたは 'GHC8でクラスレベルでD '@トップを書くことができますか? – jakubdaniel
私たちはできないと思います。デフォルトでは、 'forall'バインド型の変数は' @ 'で適用できますが、 'Domain'メソッドの型に' forall d。'を書くことはできません。私は '@'がクラスメソッドでうまく動作し、クラス型のパラメータの順番で使用できることを発見しました。 –