Created
March 27, 2020 02:02
-
-
Save jlavelle/1dd9f184c5855bd0b3a315c8748e6d63 to your computer and use it in GitHub Desktop.
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
module Choose where | |
import Prelude | |
import Data.Symbol (class IsSymbol, SProxy, reflectSymbol) | |
import Data.Variant (Variant) | |
import Data.Variant.Internal (VariantRep(..)) | |
import Prim.Row (class Cons) | |
import Record.Unsafe (unsafeGet) | |
import Unsafe.Coerce (unsafeCoerce) | |
data HasField (r :: # Type) = HasField String | |
hasField :: forall s a r' r. IsSymbol s => Cons s a r' r => SProxy s -> HasField r | |
hasField s = HasField $ reflectSymbol s | |
choose :: forall r. HasField r -> Record r -> Variant r | |
choose (HasField k) r = coerceV $ VariantRep { type: k, value: unsafeGet k r } | |
where | |
coerceV :: forall a. VariantRep a -> Variant r | |
coerceV = unsafeCoerce |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment