Hacker News new | ask | show | jobs
by jmtd 2323 days ago
> but the fact that a two records can't share field names

That is awkward sometimes yes. Record fields are functions, and you can't have two functions with the same name in the same namespace.

You can, however, use namespaces to import two separate modules with conflicting names. It does mean you have to define the two different records in two different modules.

If, you want different records to have common fields because they are conceptually related, you probably want to use type classes.

1 comments

> If, you want different records to have common fields because they are conceptually related, you probably want to use type classes.

I'm not a fan of ad-hoc typeclasses. I know that various approaches in modern Haskell advocate for them, but I think that ad-hoc typeclasses are a smell for overuse of typeclasses when plain-old data types should suffice.

I am a very big proponent of demanding that typeclasses have associated laws. Otherwise you can descend into the same hierarchy mess that plagues statically-typed class-based languages. And sometimes you just want to have different fields be named the same thing without an underlying profound relationship between the two.