関数型プログラミング言語Haskell Part11
■ このスレッドは過去ログ倉庫に格納されています
0692デフォルトの名無しさん
2010/03/16(火) 22:40:02class Class1 a where
func1 :: (Class2 b) => a -> b
class Class2 a where
func2 :: a -> String
newtype Type1 = Type1 ()
newtype Type2 = Type2 ()
instance Class1 Type1 where
func1 t = Type2 ()
instance Class2 Type2 where
func2 t = "Type2"
コンパイルしようとすると func1 t = Type2 () の部分で
Couldn't match expected type `b' against inferred type `Type2'
`b' is a rigid type variable bound by
the type signature for `func1' at ...
というようなエラーが出る。
rigid type variable をキーワードにしてググってみたけど、いまいち理解できません。
どなたか、エラーの意味と解決策を説明して頂けないでしょうか。
やりたいことは、Class1 クラスの様々なインスタンス型が、
それぞれ Class2 の様々なインスタンス型を返す仕組みを作ることです。
オブジェクト指向で言う Abstract Factory パターンみたいなことです。
■ このスレッドは過去ログ倉庫に格納されています