Skip to content

Instantly share code, notes, and snippets.

@dfithian
Last active January 25, 2019 19:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dfithian/da69fa0187631e7cb9911b0d45c2cba2 to your computer and use it in GitHub Desktop.
Save dfithian/da69fa0187631e7cb9911b0d45c2cba2 to your computer and use it in GitHub Desktop.

Title

Parameterize your Haskell types! Sometimes.

Format

Educational Session (50m)

Audience

Intermediate

Elevator Pitch

Ever experimented with parameterized types? This talk explores how you can use parameterized types to enhance the expressiveness of your data structures, with in-depth examples of how much you can express if you drink the Kool Aid.

Description

In the strongly-typed world, everyone agrees we want to represent the space of possible values using an appropriate type. The only problem is there are so many techniques to choose from! There are vanilla records, row types, parameterized types, and more. So why choose parameterized types? The answer: profunctors!

In this talk, we'll weigh the tradeoffs of parameterizing types as opposed to alternatives before exploring the world of profunctors, and how they enable a richer coding vocabulary for defining everyday data structures/working with deeply nested configuration files. We will see how to solve this common problem in software development using FP techniques and a new library built for this purpose: Interpolator. Interpolator is a new library that uses these techniques to provide a well-typed interface for substitution of runtime values into a nested data structure, without having to redefine the types. We'll get to work defining the necessary records, instances, and type aliases, and investigate several examples with increasing complexity.

NOTE While "profunctor" may seem like a scary word, hopefully this talk will eliminate some of its mystique. Specifically, we'll make sure that everyone understands what a profunctor does before moving on. This talk expects the attendee to have experience with Haskell. While not the focus of this talk, applicatives, monads, and monad transformers will make appearances.

Notes

Motivation

Parameterizing types is compelling in particular because it has proven to be an effective interface for abstracting database tables in the Opaleye library, and I want to draw upon the motivations, similarities, and differences for it in the Interpolator library. My hope is that by showing these similarities in a simpler setting others will be less intimidated by so called "advanced" concepts like profunctor.

Tags

  • Haskell
  • Type theory
  • Generic programming
@mossprescott
Copy link

Great concept! Wish I had (helped) come up with it :-D

What do you think about flipping the pitch a bit so it's something like "Learn how to define your data in a simple way and get runtime configuration for free — plus see how Profunctor surprisingly saves the day"? I think that might bring in people who don't know they want to learn about Profunctor. To be honest, I still don't really understand how Profunctor solves this problem, so I obviously need to go to this talk.

@dfithian
Copy link
Author

@mossprescott

You did come up with it! How can I give you kudos? Do you want to submit the talk together?

I like that suggestion, and it's the second time I've gotten it. I'll give it a try.

@mossprescott
Copy link

This is pretty good as is. It says what problem is being solved, and it teases Profunctor as (part of) the solution.

I think you could do better than "a translation interface for runtime variables" as a summary of what Interpolator is for, but I'm finding it's hard to put into a few words. Maybe "substitution of runtime values into a nested data structure". Or, something involving "typed" and "template language" (in the sense of https://en.wikipedia.org/wiki/Template_processor).

You could make it somewhat more concrete by spelling out the point that you get a well-typed representation of your template, and another for after you've applied it to some values, without having to define it twice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment