Skip to content

Instantly share code, notes, and snippets.

@rupertlssmith
Created December 19, 2022 12:40
Show Gist options
  • Save rupertlssmith/514f0a1997f26b1df714301f70e08685 to your computer and use it in GitHub Desktop.
Save rupertlssmith/514f0a1997f26b1df714301f70e08685 to your computer and use it in GitHub Desktop.
Type hiding in Elm by using continuations.
module Existential exposing (add, impl, init, map, wrap)
impl : t -> (raise -> rep -> t)
impl constructor =
\raise rep -> constructor
wrap : (raise -> rep -> t) -> (raise -> rep -> (t -> q)) -> (raise -> rep -> q)
wrap method pipeline raise rep =
method raise rep |> pipeline raise rep
add : (rep -> t) -> (raise -> rep -> (t -> q)) -> (raise -> rep -> q)
add method pipeline raise rep =
method rep |> pipeline raise rep
map : (a -> b) -> (raise -> rep -> a) -> (raise -> rep -> b)
map op pipeline raise rep =
pipeline raise rep |> op
init : ((rep -> sealed) -> flags -> output) -> ((rep -> sealed) -> rep -> sealed) -> flags -> output
init initRep pipeline flags =
let
raise : rep -> sealed
raise rep =
pipeline raise rep
in
initRep raise flags
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment