Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.




FYI that pattern is useful even in the absence of orphans.


Interesting, where?


I 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/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.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: