Created
March 5, 2016 02:42
-
-
Save aavogt/970b892c78a686ca8ee2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 CPP #-} | |
| {-# LANGUAGE FlexibleContexts #-} | |
| {-# LANGUAGE FlexibleInstances #-} | |
| {-# LANGUAGE MultiParamTypeClasses #-} | |
| {-# LANGUAGE DataKinds #-} | |
| {-# LANGUAGE KindSignatures #-} | |
| {-# LANGUAGE TypeFamilies #-} | |
| import GHC.TypeLits | |
| import Data.Proxy | |
| type family UpdateType (l :: Symbol) s b | |
| type family FieldType (l :: Symbol) s | |
| type instance UpdateType "fst" (x,y) a = (a,y) | |
| type instance FieldType "fst" (x,y) = x | |
| class | |
| #ifdef CXT | |
| FieldType l (UpdateType l s b) ~ b => | |
| #endif | |
| SetField l s b where | |
| setField :: Proxy l -> s -> b -> UpdateType l s b | |
| instance SetField "fst" (a,b) x where | |
| setField _ (a,b) x = (x,b) | |
| test1 xs x = setField (Proxy :: Proxy "fst") xs x :: ( Int , ()) | |
| {- with | |
| ghci-8.0.0.20160204 -DCXT | |
| ghci-7.8.4 | |
| -- just not 7.10 | |
| test1 | |
| :: (SetField "fst" s Int, UpdateType "fst" s Int ~ (Int, ())) => | |
| s -> Int -> (Int, ()) | |
| without -DCXT | |
| test1 | |
| :: (SetField "fst" s b, UpdateType "fst" s b ~ (Int, ())) => | |
| s -> b -> (Int, ()) | |
| -} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment