Last active
March 30, 2016 11:26
-
-
Save nc6/c5cb8e62b3edd9bb5eed8d9291ad57f8 to your computer and use it in GitHub Desktop.
Example of using new Vinyl ElField (open universe field types)
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
{-# LANGUAGE DataKinds, FlexibleContexts, TypeOperators #-} | |
module Main where | |
import Data.Proxy | |
import Data.Vinyl | |
import Data.Vinyl.Derived | |
import Data.Vinyl.Functor | |
import Control.Applicative | |
foo :: Proxy '("foo", String) | |
foo = Proxy | |
bar :: Proxy '("bar", Int) | |
bar = Proxy | |
type Fields = ['("foo", String), '("bar", Int)] | |
rec1 :: FieldRec Fields | |
rec1 = (foo =: "Hello") | |
<+> (bar =: 2) | |
<+> RNil | |
main :: IO () | |
main = do | |
putStrLn $ printBaz rec1 | |
printBaz :: ('("foo", String) ∈ fields) => FieldRec fields -> String | |
printBaz = getField . rget foo | |
setBar :: ('("bar", Int) ∈ fields) => FieldRec fields -> Int -> FieldRec fields | |
setBar fields v = rreplace (bar =: v) fields |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment