Skip to content

Instantly share code, notes, and snippets.

@dminuoso
Last active November 3, 2020 15:06
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 dminuoso/79855d359ea2d21a8184e235870ecb44 to your computer and use it in GitHub Desktop.
Save dminuoso/79855d359ea2d21a8184e235870ecb44 to your computer and use it in GitHub Desktop.
flip :: (a -> b -> c) -> b -> a -> c
id :: a -> a
--------------------------------------------------------------------------------
Given:
t = flip id
Step 1: Instantiate with unification variables:
(1) flip id :: _w
(2) flip :: (_s -> _t -> _u) -> _t -> _s -> _u
(3) id :: _v -> _v
Using (2) and (1) we get
(4) _w ~ (_t -> _s -> _u)
Substitute (4) into (1)
(5) flip id :: _t -> _s -> _u
From application we also get:
(6) (_v -> _v) ~ (_s -> _t -> u)
Which gives us:
(7) _v ~ _s
(8) _v ~ (_t -> _u)
Which gives us:
(9) _s ~ (_t -> _u)
Substitute (9) into (5)
10) flip id :: _t -> (_t -> _u) -> _u
We cant make any more progress, generalize over all left overs:
flip id :: a -> (a -> b) -> b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment