Created
July 2, 2013 01:48
-
-
Save acowley/5906221 to your computer and use it in GitHub Desktop.
Example of vinyl subtyping.
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 #-} | |
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