(私は他のすべての些細な部分を抽象化している)Haskell:同じ名前空間の "where"節に型変数がありますか?
data T s = T (s -> s)
foo :: T s -> s -> s
foo (T f) x = bar x where
bar :: s -> s
bar a = f a
私は
Couldn't match expected type `s1' with actual type `s'
`s1' is a rigid type variable bound by
the type signature for bar :: s1 -> s1 at /tmp/test.hs:5:12
`s' is a rigid type variable bound by
the type signature for foo :: T s -> s -> s at /tmp/test.hs:3:8
In the return type of a call of `f'
In the expression: f a
In an equation for `bar': bar a = f a
エラーを以下しまった私の推測では、bar
の署名で型変数が共有していないということでしたfoo
という名前空間を使用しているため、コンパイラは2つの型が実際に同じ型を意味していると推測することはできません。
私はこのページScoped type variablesを見つけました。私は{-# LANGUAGE ScopedTypeVariables #-}
を使うことができますが、それは役に立たなかったことを示唆しています。私は同じエラーがあります。
wiki上の例として、 'ScopedTypeVariables'で実際に使用するには' foo'の型シグネチャに 'forall s'が必要です。 –