Skip to content

Instantly share code, notes, and snippets.

@acowley
Created July 2, 2013 01:48
Show Gist options
  • Save acowley/5906221 to your computer and use it in GitHub Desktop.
Save acowley/5906221 to your computer and use it in GitHub Desktop.
Example of vinyl subtyping.
{-# LANGUAGE DataKinds, FlexibleContexts, TypeOperators #-}
import Data.Vinyl
type Model = "model" ::: String
model :: Model
model = Field
type Car = PlainRec ["company":::String, Model, "year":::Int]
showModel :: (i <: PlainRec '[Model]) => i -> IO ()
showModel = putStrLn . rmodel . cast
where rmodel :: PlainRec '[Model] -> String
rmodel = rGet model
test :: IO ()
test = showModel car
where car :: Car
car = Field =: "Ford" <+> Field =: "Fusion" <+> Field =: 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment