Skip to content

Instantly share code, notes, and snippets.

@natefaubion
Last active March 1, 2020 20:15
Show Gist options
  • Select an option

  • Save natefaubion/5efc2e487042ac0aa42ecd804e13cc04 to your computer and use it in GitHub Desktop.

Select an option

Save natefaubion/5efc2e487042ac0aa42ecd804e13cc04 to your computer and use it in GitHub Desktop.
module Deref where
import Prelude hiding (map, apply, pure)
import Record as Record
import Prelude as Prelude
import Prim.Row as Row
import Data.Symbol (SProxy(..), class IsSymbol)
data Deref r1 (r2 :: # Type) (r3 :: # Type) a = Deref ({ | r1 } -> a)
deref ::
forall r1 r2 r3 rx sym a.
IsSymbol sym =>
Row.Cons sym a rx r1 =>
Row.Cons sym a r2 r3 =>
SProxy sym ->
Deref r1 r2 r3 a
deref = Deref <<< Record.get
pure :: forall r1 r2 r3 a. a -> Deref r1 r2 r3 a
pure = Deref <<< const
map :: forall r1 r2 r3 a b. (a -> b) -> Deref r1 r2 r3 a -> Deref r1 r2 r3 b
map f (Deref k) = Deref (Prelude.map f k)
apply :: forall r1 r2 r3 r4 a b. Deref r1 r2 r3 (a -> b) -> Deref r1 r3 r4 a -> Deref r1 r2 r4 b
apply (Deref a) (Deref b) = Deref (Prelude.apply a b)
test = ado
a <- deref (SProxy :: _ "a")
b <- deref (SProxy :: _ "b")
in a + b
runDeref :: forall r a. Deref r () r a -> { | r } -> a
runDeref (Deref k) = k
result = runDeref test { a: 1, b: 2 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment