documentation/errors/OrphanInstance.md at master · purescript/documentation · GitHub
Skip to content

Latest commit

 

History

History
41 lines (25 loc) · 1.04 KB

OrphanInstance.md

File metadata and controls

41 lines (25 loc) · 1.04 KB

OrphanInstance Error

Example

module A where

class SomeClass a
module B where

data SomeData
module C where

import A
import B

instance someInstance :: SomeClass SomeData

Cause

This error occurs when an instance is declared outside of the module that declares the class it is for, and also none of the instance's types are declared in the same module.

Above, someInstance is an orphan here as it is defined in a module separate from both SomeData and SomeClass.

Fix

  • If possible, move the instance into an allowed module.
  • Consider adding a newtype, and defining the instance in the same module as the newtype.

Notes

Orphan Instances with Functional Dependencies

When using type classes involving functional dependencies, the rules for orphan instances are a little more complicated. They are explained in this blog post.