Skip to content

Instantly share code, notes, and snippets.

@nc6
Last active March 30, 2016 11:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nc6/c5cb8e62b3edd9bb5eed8d9291ad57f8 to your computer and use it in GitHub Desktop.
Save nc6/c5cb8e62b3edd9bb5eed8d9291ad57f8 to your computer and use it in GitHub Desktop.
Example of using new Vinyl ElField (open universe field types)
{-# 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