GADT. , , , . PolyKinds, .
, , .
data Sort = Base | Compound
, . .
data WeaponPart :: Sort -> * where
WInt :: Int -> WeaponPart Base
WHash :: Map.Map String Int -> WeaponPart Base
WNull :: WeaponPart Base
WTrans :: (Some WeaponPart -> Some WeaponPart) -> WeaponPart Compound
& lsquo; & rsquo; , :
data Some p where
Wit :: p x -> Some p
, x , & lsquo; evidence & rsquo; x & lsquo; & rsquo; p. : Some data, newtype GHC newtype s.
Sort - . , , Some p -> ... forall x. p x -> ....
instance Show (WeaponPart x) where
show (WInt x) = "WInt " ++ (show x)
show (WHash x) = "WHash " ++ (show x)
show (WTrans _) = "WTrans"
show WNull = "WNull"
Sort - : .
cold :: Some WeaponPart -> Some WeaponPart
cold (Wit (WInt x)) = Wit (WHash (Map.singleton "frost" x))
cold (Wit (WHash x)) = Wit (WHash $ Map.insertWith (+) "frost" 5 x)
cold (Wit (WTrans x)) = cold $ x (Wit (WInt 5))
cold (Wit WNull) = cold $ Wit (WInt 5)
Wit , .
ofTheAbyss :: WeaponPart Compound -> Some WeaponPart
ofTheAbyss (WTrans x) = x (Wit (WTrans x))
. : , , , - , . , .