我有一个函数,它在where子句中定义了一个值,我想给它一个显式的类型注释.注释需要使用顶级函数中的类型变量,因此我的理解是我需要使用ScopedTypeVariables.这是问题的最小减少:
{-# LANGUAGE ScopedTypeVariables #-}
import Control.Monad.Trans.Except
import Data.Functor.Identity
f :: ExceptT String Identity a -> Maybe a
f m = Nothing
where x :: Identity (Either String a)
x = runExceptT m
Run Code Online (Sandbox Code Playgroud)
此代码不能进行类型检查.它失败并显示以下错误消息:
Couldn't match type ‘a’ with ‘a1’
‘a’ is a rigid type variable bound by
the type signature for f :: ExceptT String Identity a -> Maybe a
at src/Lib.hs:20:6
‘a1’ is a rigid type variable bound by
the type signature …Run Code Online (Sandbox Code Playgroud)