为什么 Haskell PVP 将新函数描述为非破坏性的?

Jan*_*sen 4 versioning compatibility haskell

假设我有以下代码

module A where

  x :: Int 
  x = 5

module Main where

  import A
  import Lib
  
  main :: IO ()
  main = print (x + y)
Run Code Online (Sandbox Code Playgroud)

以及在外部库中

module Lib where

  y :: Int
  y = 10
Run Code Online (Sandbox Code Playgroud)

一切都很好,该库的版本为 v0.1.0.0,我将其包含在边界中mylib == 0.1.*

现在,该名称x :: Int已添加到 MyLib 的导出列表中,并且新版本已发布。它的版本是 v0.1.1.0,如PVP 流程图所示:

在这种情况下,只有[...]函数[...]被添加到库的导出接口中。不会导致破损 [...]

这个说法如何正确呢?当然我的代码不再编译。因为它不知道x从哪里拉。

Nou*_*are 6

您可以通过防御性导入方式来防止损坏。Haskell wiki 有一篇关于它的文章

我们建议重点关注以下两种导入方式:

import qualified Very.Special.Module as VSM
import Another.Important.Module (printf, (<|>), )
Run Code Online (Sandbox Code Playgroud)

代替

import Very.Special.Module
import Another.Important.Module hiding (open, close, )
Run Code Online (Sandbox Code Playgroud)

而PVP规则也是他们提倡露骨风格的原因之一。