gpt4 book ai didi

haskell - 没有 ScopedTypeVariables 的外部边界类型声明

转载 作者:行者123 更新时间:2023-12-03 13:38:33 25 4
gpt4 key购买 nike

我有以下工作定义:

{-# LANGUAGE ScopedTypeVariables #-}
module Control.Retry where

import Prelude hiding (catch)
import Control.Exception
import Control.Concurrent

retrying [] action = action
retrying (i:is) action = catch action processError
where
processError (e :: IOException) = threadDelay i >> retrying is action

出于好奇,我想知道如何在不使用 ScopedTypeVariables 的情况下重新实现它pragma,或者我是否可以,以及 processError 的推断类型声明是什么?实际上是,因为指定 processError :: IOException -> IO a使其无法编译。

最佳答案

另一种选择,可能比 asTypeOf 更简洁:

retrying [] action = action 
retrying (i:is) action = catch action processError
where
processError e = threadDelay i >> retrying is action
where
_ = e :: IOException

不确定这是否是惯用的;我只是编造出来的,它奏效了。

关于haskell - 没有 ScopedTypeVariables 的外部边界类型声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13828602/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com