Skip to content

Instantly share code, notes, and snippets.

@crdueck
Created December 6, 2020 00:41
Show Gist options
  • Save crdueck/5616b77a13be70b1530b0e243650b475 to your computer and use it in GitHub Desktop.
Save crdueck/5616b77a13be70b1530b0e243650b475 to your computer and use it in GitHub Desktop.
Type family inference
{-# LANGUAGE GADTs, TypeFamilies, DataKinds, TypeOperators #-}
import Type.Reflection
type family Map f xs where
Map f '[] = '[]
Map f (x ': xs) = f x ': Map f xs
data HList xs where
HNil :: HList '[]
HCons :: a -> HList xs -> HList (a ': xs)
foo :: HList (Map TypeRep xs) -> HList xs
foo HNil = HNil
{-
main.hs:15:12: error:
* Could not deduce: xs ~ '[]
from the context: Map TypeRep xs ~ '[]
bound by a pattern with constructor: HNil :: HList '[],
in an equation for `foo'
at main.hs:15:5-8
`xs' is a rigid type variable bound by
the type signature for:
foo :: forall (m :: * -> *) (xs :: [*]).
Monad m =>
HList (Map TypeRep xs) -> m (HList xs)
at main.hs:14:1-56
Expected type: m (HList xs)
Actual type: m (HList '[])
* In the expression: return HNil
In an equation for `foo': foo HNil = return HNil
* Relevant bindings include
foo :: HList (Map TypeRep xs) -> m (HList xs)
(bound at main.hs:15:1)
|
15 | foo HNil = return HNil
| ^^^^^^^^^^^
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment