Row polymorphism crash course

// Works for any record with the fields width, height : Float
area2d v = v.width * v.height
f : forall row1. {a: Int, …row1} -> Int
g : forall row2. {b: String, …row2} -> Int
h x = f x + g x
f : {a: Int, …row3} -> Int
g : {b: String, …row4} -> Int
x : {a: Int, …row3}
x : {b: String, …row4}
{a: Int, …row3} = {b: String, …row4}
row3 = {b: String, …row5}
row4 = {a: Int, …row5}
{a: Int, b: String, …row5} = {b: String, a: Int, …row5}
{a: Int, b: String, …row5} = {a: Int, b: String, …row5}
h : forall row5. {a: Int, b: String, …row5} -> Int
f : {a: Int, …row3} -> Int
g : {a: String, …row4} -> Int
{a: Int, …row3} = {a: String, …row4}
Int = String

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Joakim Ahnfelt-Rønne

Joakim Ahnfelt-Rønne

25 Followers

MSc Computer Science, working with functional programming in the industry — github.com/ahnfelt