Skip to content

Instantly share code, notes, and snippets.

@joelburget
Created June 7, 2018 00:49
Show Gist options
  • Save joelburget/40a94ff803c93ee2ebe27fdf7e32701e to your computer and use it in GitHub Desktop.
Save joelburget/40a94ff803c93ee2ebe27fdf7e32701e to your computer and use it in GitHub Desktop.
import Data.Vinyl
-- import Data.Vinyl.Functor
type LifeForm a =
"name" ::: String
: "age" ::: Int
: "sleeping" ::: Bool
: a
type LifeForm' a = FieldRec (LifeForm a)
jon :: LifeForm' '[]
jon = #name =: "jon"
:& #age =: 23
:& #sleeping =: False
:& RNil
tucker :: LifeForm' '["master" ::: LifeForm' '[]]
tucker = #name =: "tucker"
:& #age =: 9
:& #sleeping =: True
:& #master =: jon
:& RNil
wakeUp
:: HasField record "sleeping" fs Bool
=> record ElField fs
-> record ElField fs
wakeUp = rputf #sleeping False
jon' :: LifeForm' '[]
jon' = wakeUp jon
tucker' :: LifeForm' '["master" ::: LifeForm' '[]]
tucker' = wakeUp tucker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment