You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Haskell中如何弃用特定的类型类实例?

在Haskell中为FromRow实例的方法添加DEPRECATED标记的正确方式

可以实现,你遇到的解析错误是因为DEPRECATED编译指令的放置位置不符合Haskell语法规范。

Haskell的编译pragma(如DEPRECATED)属于顶层声明,不能放在缩进的实例方法定义块内部。正确的做法是将DEPRECATED pragma放在要标记的实体上方:

正确代码示例

{-# DEPRECATED fromRow @Job "Please do not depend on the FromRow instance of the Job type. It does not handle optional features, such as job-results and job-workflows. Depending upon your scenario, use 'jobRowParserSimple' or 'jobRowParserWithWorkflow' directly." #-}
instance FromRow Job where
  fromRow = jobRowParserSimple

补充说明

  1. 如果不需要精确限定到Job类型的fromRow,也可以简化为:
{-# DEPRECATED fromRow "Please do not depend on the FromRow instance of the Job type. It does not handle optional features, such as job-results and job-workflows. Depending upon your scenario, use 'jobRowParserSimple' or 'jobRowParserWithWorkflow' directly." #-}
instance FromRow Job where
  fromRow = jobRowParserSimple

不过添加@Job类型限定能更精准地标记目标,避免影响其他类型的fromRow方法。

  1. 若要标记整个FromRow Job实例而非单个方法,可这样写:
{-# DEPRECATED instance FromRow Job "Please do not depend on the FromRow instance of the Job type. Use 'jobRowParserSimple' or 'jobRowParserWithWorkflow' directly instead." #-}
instance FromRow Job where
  fromRow = jobRowParserSimple

内容的提问来源于stack exchange,提问作者Saurabh Nanda

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 17:52:12