Skip to content

Instantly share code, notes, and snippets.

@chrisdone
Last active February 8, 2017 17:26
Show Gist options
  • Save chrisdone/6a9b3c671f0ef4a2834ffb7ad6c9eaca to your computer and use it in GitHub Desktop.
Save chrisdone/6a9b3c671f0ef4a2834ffb7ad6c9eaca to your computer and use it in GitHub Desktop.
labels vs vinyl vs record vs lens

labels vs vinyl vs record vs lens

Advantages and disadvantages of each are explored here.

vinyl

Pros

  • Support arbitrary number of fields
  • Supports projecting and narrow and things like that quite well
  • Apparently supports lens
  • Field order doesn't change the type

Cons

  • Requires you to declare fields ahead of time

  • Apparently takes up runtime space

  • Types are fairly complex

  • Creating values is kind of a drag (lots of operators and nil):

          (SName =:: "tucker")
       :& (SAge =:: 9)
       :& (SSleeping =:: True)
       :& (SMaster =:: jon)
       :& RNil
    
  • Likely supports projection

Unclear

  • Type inference is good?
  • Has rows? Like Has field record => record -> .... Unclear from the docs.

labels

Pros

  • Does not require you to declare fields ahead of time
  • No runtime overhead over regular tuples
  • Supports projection
  • Supports lenses via lens #foo e.g. set (lens #foo . lens #bar) .. ..
  • Type inference is good
  • Type signatures are short: ("foo" := Int, "bar" := String)
  • Creating values is trivial: (#foo := 123, #bar := "hi")
  • Supports rows: (Has "foo" r, Has "bar" r) => r -> ...

Cons

  • Field order matters
  • Instance explosion for Has class: haddocks
  • Only supports 24 fields at a time

record

Pros

  • A limited number of fields (like labels)
  • Does not require you to declare fields ahead of time
  • Types are simple
  • Supports (or: requires) lenses

Cons

  • Field order matters
  • Doesn't require declaring fields ahead of time
  • Requires a preprocessor (for creating types, values, updates, etc.)
  • Type inference is good
  • Value creation is pretty clean syntax
  • Doesn't support projection/narrowing/reshaping

Unclear

  • Supports rows? Unknown

lens

Pros

  • Supports composable setters/getters
  • Supports "rows" like (HasName r, HasAge r) => r -> ...

Cons

  • Requires declaring things ahead of time
  • Isn't really a record system
  • Doesn't support projection/narrowing/reshaping
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment