Skip to content

Instantly share code, notes, and snippets.

@kosmikus
Created January 9, 2016 16:33
Show Gist options
  • Save kosmikus/8348f0030d2fa7e6e149 to your computer and use it in GitHub Desktop.
Save kosmikus/8348f0030d2fa7e6e149 to your computer and use it in GitHub Desktop.
Strange TypeError behaviour
{-# LANGUAGE TypeInType, TypeFamilies, UndecidableInstances #-}
{-# LANGUAGE UndecidableInstances #-}
import Data.Kind
import GHC.TypeLits (TypeError, ErrorMessage(..))
type family Resolve (t :: Type -> Type) :: Type -> Type where
Resolve _ = TypeError (Text "ERROR")
-- testOK :: Resolve [] Int
-- testOK = []
--
-- • ERROR
-- • In the expression: []
-- In an equation for ‘testOK’: testOK = []
--
-- testNOTOK1 :: Resolve [] Int
-- testNOTOK1 = ()
--
-- • Couldn't match type ‘()’ with ‘(TypeError ...)’
-- Expected type: Resolve [] Int
-- Actual type: ()
-- • In the expression: ()
-- In an equation for ‘testNOTOK1’: testNOTOK1 = ()
--
-- testNOTOK2 :: Resolve [] Int
-- testNOTOK2 = 1
--
-- • No instance for (Num (TypeError ...))
-- arising from the literal ‘1’
-- • In the expression: 1
-- In an equation for ‘testNOTOK2’: testNOTOK2 = 1
--
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment