Created
June 16, 2024 00:49
-
-
Save chiroptical/e1932eb80ae4897a30c2fbb28a7583c2 to your computer and use it in GitHub Desktop.
Upstar Profunctor instance in Gleam
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// dimap :: (a -> b) -> (c -> d) -> p b c -> p a d | |
// p b c -> c b | |
// p a d -> d a | |
pub type Profunctor(p, q, a, b, c, d) { | |
Profunctor(dimap: fn(#(fn(a) -> b, fn(c) -> d, p)) -> q) | |
} | |
pub type Upstar(f, a) { | |
Upstar(run: fn(a) -> f) | |
} | |
pub fn upstar_profunctor() -> Profunctor(Upstar(c, b), Upstar(d, a), a, b, c, d) { | |
let dimap = fn(inp: #(fn(a) -> b, fn(c) -> d, Upstar(c, b))) { | |
let f = inp.0 | |
let g = inp.1 | |
let Upstar(run) = inp.2 | |
Upstar(run: fn(x) { g(run(f(x))) }) | |
} | |
Profunctor(dimap) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment