gre*_*ake 5 haskell pattern-synonyms
假设我有以下代码
\ndata F a where\n F :: Typeable a => F a\n\nasType :: forall b a. Typeable b => F a -> Maybe (a :~: b, F b)\nasType e@F{} = case eqT @b @a of\n Just Refl -> Just (Refl, e)\n Nothing -> Nothing\n\npattern AsType :: forall a b. Typeable a => (a ~ b) => F a -> F b\npattern AsType e <- (asType @a -> Just (Refl, e))\n\npattern AsInt :: Typeable b\' => (Int ~ b\') => F Int -> F b\'\npattern AsInt e <- AsType e -- doesn\'t compile\nRun Code Online (Sandbox Code Playgroud)\na如果我可以显式实例化AsType 中的类型参数,并且使用它的Int类型参数可能会起作用。bb\'
我试图给AsType它一个显式的类型签名((AsType :: \xe2\x80\xa6) e),但它是一个解析错误。我尝试使用类型应用程序 \xe2\x80\x94 也无济于事。
如果可能的话,我怎样才能让它发挥作用?如果没有,为什么?
\n(我可以AsInt通过模式视图来实现asType,但它并不有趣而且更冗长)
| 归档时间: |
|
| 查看次数: |
122 次 |
| 最近记录: |