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
补充说明
- 如果不需要精确限定到
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方法。
- 若要标记整个
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
相关产品推荐
相关产品推荐

