Last active
March 1, 2020 20:15
-
-
Save natefaubion/5efc2e487042ac0aa42ecd804e13cc04 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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