blob: 667c309da1d110591eee79e39a0bb0f3007d0eb0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
module Test where
import GHC.TypeLits
data Pet (a :: k) = Pet
{ name :: String
} deriving Show
class SetField (name :: Symbol) s t b | name t -> s b
, name s -> t b where
setField :: b -> s -> t
instance
( SetField "name" (Pet a) (Pet b) String
) => SetField "name" (Pet (a :: k)) (Pet (b :: k')) String where
setField v d = d { name = v }
loop = setField @"name" 'c' (Pet "hi")
|