forall
を用いたデータ型について質問です.以下の通りに`AnyBar`型を構成した場合に,値を取り出す関数を書きたいです.
{-# LANGUAGE ExistentialQuantification #-} module Bar where data AnyBar b = forall a. AnyBar a (a -> b) argBar :: AnyBar b -> b argBar (AnyBar x f) = f x letBar :: AnyBar b -> b letBar ab = let AnyBar x f = ab in f x
2通りのうち`letBar`だけエラーになりました.
src/Bar.hs:11:26: error: • Couldn't match expected type 'p1' with actual type 'a -> b' 'p1' is a rigid type variable bound by the inferred types of x :: p f :: p1 at src/Bar.hs:11:17-31 • In the pattern: AnyBar x f In a pattern binding: AnyBar x f = ab In the expression: let AnyBar x f = ab in f x • Relevant bindings include ab :: AnyBar b (bound at src/Bar.hs:11:8) letBar :: AnyBar b -> b (bound at src/Bar.hs:11:1) | 11 | letBar ab = let AnyBar x f = ab in f x | ^
原因が分からないです.見た感じだと両者ともパターンマッチしてるだけで差異が現れるとは思えません.