Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Haskell 在本地绑定中查找表达式的类型_Haskell - Fatal编程技术网

Haskell 在本地绑定中查找表达式的类型

Haskell 在本地绑定中查找表达式的类型,haskell,Haskell,有没有办法通过重写下面的实例,在下面的代码中找到shift的类型?是因为它是本地绑定(在where构造中),所以在下面尝试调用它时找不到它的类型的原因吗 class CoMonad m其中 摘录::m a->a (硕士->硕士 实例(幺半群s)=>CoMonad((->)s),其中 摘录=($mempty) f rr(s t) :t移位 :1:1:错误:变量不在范围内:shift 一种可能性是使用通配符给shift一个不完整的签名: class CoMonad m where extract

有没有办法通过重写下面的实例,在下面的代码中找到
shift
的类型?是因为它是本地绑定(在where构造中),所以在下面尝试调用它时找不到它的类型的原因吗

class CoMonad m其中
摘录::m a->a
(硕士->硕士
实例(幺半群s)=>CoMonad((->)s),其中
摘录=($mempty)
f rr(s t)
:t移位
:1:1:错误:变量不在范围内:shift

一种可能性是使用通配符给
shift
一个不完整的签名:

class CoMonad m where
  extract :: m a -> a
  (<<=) :: (m a -> b) -> m a -> m b
instance (Monoid s) => CoMonad ((->) s) where
  extract = ($ mempty)
  f <<= r = \ t -> (f . shift t) r
     where
     shift :: _ 
     shift t rr = \ s -> rr (s <> t)
如果您还没有实际添加本地绑定,那么键入的孔(在下面的示例中为shift)将以类似的方式为您提供缺少的任何内容的推断类型

\ t -> (f . _shift) r

您还可以内联写入通配符(
\t->(f.(shift::)))r
)或将术语替换为键入的孔(
\t->(f.\u shift)r
<interactive>:9:15: error:
    • Found type wildcard ‘_’ standing for ‘s -> (s -> t) -> s -> t’
      Where: ‘t’ is a rigid type variable bound by
               the inferred type of shift :: s -> (s -> t) -> s -> t
               at <interactive>:10:6-36
             ‘s’ is a rigid type variable bound by
               the instance declaration
               at <interactive>:5:10-39
      To use the inferred type, enable PartialTypeSignatures
    • In the type signature: shift :: _
      In an equation for ‘<<=’:
          f <<= r
            = ...
            where
                ...
      In the instance declaration for ‘CoMonad ((->) s)’
    • Relevant bindings include
        r :: s -> a (bound at <interactive>:7:9)
        f :: (s -> a) -> b (bound at <interactive>:7:3)
        (<<=) :: ((s -> a) -> b) -> (s -> a) -> s -> b
          (bound at <interactive>:7:5)
(\ t -> (f . (shift :: _)) r
\ t -> (f . _shift) r