4
$\begingroup$

Let's say I have the following code

module A where

  x :: Int 
  x = 5

module Main where

  import A
  import Lib
  
  main :: IO ()
  main = print (x + y)

and in an external library

module Lib where

  y :: Int
  y = 10

All well and good, the library is at v0.1.0.0 and I include it with bounds mylib == 0.1.*

Now, the name x :: Int is added to the export list of MyLib and a new release is out. It's version is v0.1.1.0, as suggested in the PVP flowchart:

In this case, only [...] functions [...] were added to the library's exported interface. No breakage [...] could result

How is this assertion correct? Surely my code no longer compiles. Since it doesn't know where to pull x from.

$\endgroup$
1
  • 1
    $\begingroup$ It's not mylib's interface alone that causes the breakage, which is what a major-number bump would indicate. People not using A won't see a problem with the introduction of x. (I.e, it's not mylib's fault you aren't using import qualified A :) ) $\endgroup$ Commented Feb 23, 2024 at 21:51

1 Answer 1

6
$\begingroup$

You can prevent breakage with a defensive importing style. The Haskell wiki has an article about it:

We recommend to focus on the following two forms of import:

import qualified Very.Special.Module as VSM
import Another.Important.Module (printf, (<|>), )

instead of

import Very.Special.Module
import Another.Important.Module hiding (open, close, )

And the PVP rules are one of the reasons they advocate for the explicit style.

$\endgroup$
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.