4 ms·
Haskell automatically imports all typeclass definitions (equivalent to traits) when you import a module, so you sometimes see lines like `import Foo.Bar ()` W
by wyager 5y ago
Haskell automatically imports all typeclass definitions (equivalent to traits) when you import a module, so you sometimes see lines like
`import Foo.Bar ()`
Which looks like it's just importing nothing at all (`()`) but is actually pulling in some traits and nothing else.
You don't see this often because "orphan instances" (instances defined in a file besides the location of the trait definition or the type definition) are discouraged, but they do occur.
- tome 5y agoFYI that pattern is useful even in the absence of orphans.
- wyager 5y agoInteresting, where?
- tome 5y agoI use it in test suites, where the tests are simply to check that something compiles, not its behaviour, for example https://github.com/tomjaguarpaw/product-profunctors/blob/faf52f0a134099ed8adb6b29ea822d48920e7ac3/Test/Main.hs#L1 https://github.com/tomjaguarpaw/product-profunctors/blob/faf... I had also thought that there was a reason one could need that pattern to import instances even in the absence of orphans, but on reflection I think I was mistaken.