Where is Safe.Coerce?

I was working on preparing my project for 0.14 and noticed that the newtype package was refusing to compile, complaining about unknown module Safe.Coerce. A quick look at its GH repo showed that it depends on the safe-coerce package, but the current package set from the prepare-0.14 branch doesn’t show that dependency, and indeed doesn’t have safe-coerce itself in packages.json, though it is present in src/groups/purescript.dhall.

It would be somewhat reasonable to expect the Safe.Coerce module to be provided by the compiler, but that also doesn’t seem to be the case, because I’m trying to compile with the most current master build (commit d056c120), which reports itself as 0.14.0-rc4.

Am I missing something or is this an actual oversight? And if so, would a pull request to package-sets be helpful?

2 Likes

It does live in the purescript/purescript-safe-coerce repo. I think it is an oversight - that it just hasn’t been added to the package-sets repo yet, and I think a PR would indeed be useful.

While the Coercible class is inside the compiler, the coerce function isn’t, and this is deliberate. It’s because everything that is built in to the compiler currently needs to not exist at runtime (for technical reasons), and coerce could be used in a context where it can’t be inlined.

4 Likes

Oh also, for future reference: everything that is built into the compiler lives inside a module whose name starts with Prim.

3 Likes

Got it, thank you @hdgarrood.
Here’s the PR: https://github.com/purescript/package-sets/pull/787

3 Likes