Да, конечно > cat Sing.hs {-# LANGUAGE TypeFamilies, DataKinds, PolyKinds, ScopedTypeVariables, TypeApplications, RankNTypes, AllowAmbiguousTypes #-} module Sing where import Prelude import Data.Typeable data Key = KeyA | KeyB f :: forall (key :: Key) . Typeable key => String f | Just Refl <- eqT @key @'KeyA = "a" | Just Refl <- eqT @key @'KeyB = "b" | otherwise = error "should be impossible but actually isn't" data family KeyC :: k test :: String test = f @KeyC > ghc Sing.hs [1 of 1] Compiling Sing ( Sing.hs, Sing.o ) > ghc --version The Glorious Glasgow Haskell Compilation System, version 9.0.1
Обсуждают сегодня