L
Size: a a a
MP
MP
AppendSymbol
"blablabla"MP
L
type (++) a b = AppendSymbol a b
type TShow :: k -> Symbol
type family TShow x
type instance TShow @Symbol x = TShowString x
type instance TShow @Nat x = TShowNat x
type instance TShow @Bool x = TShowBool x
type family TShowString x where
TShowString x = "\"" ++ x ++ "\""
type family TShowBool x where
TShowBool 'True = "True"
TShowBool 'False = "False"
type family TShowNat x where
TShowNat 0 = "0"
TShowNat 1 = "1"
TShowNat 2 = "2"
TShowNat 3 = "3"
TShowNat 4 = "4"
TShowNat 5 = "5"
TShowNat 6 = "6"
TShowNat 7 = "7"
TShowNat 8 = "8"
TShowNat 9 = "9"
TShowNat x = TShowNat (Div x 10) ++ TShowNat (Mod x 10)
MP
AA
AA
ЗП
Dijkstra s a = Codensity ((->) s) a
ЗП
не
пропустилK
Typeable
. Иначе - никакк
data X = forall a. Typeable a => X a
f :: X -> String
f (X (x :: a))
| Just Refl <- eqT @a @Int =
"int: " <> show x
| Just Refl <- eqT @a @String =
"string: " <> show x
| Just Refl <- eqT @a @Bool =
"bool: " <> show x
| otherwise = "unknown"
main = do
putStrLn (f (X (1 :: Int)))
putStrLn (f (X "hello"))
putStrLn (f (X True))
putStrLn (f (X (Just (1 :: Int))))
-- int: 1
-- string: "hello"
-- bool: True
-- unknown