Skip to content

Instantly share code, notes, and snippets.

@CRogers
Last active August 29, 2015 14:10
Show Gist options
  • Save CRogers/2b595e4401f9bfc707a4 to your computer and use it in GitHub Desktop.
Save CRogers/2b595e4401f9bfc707a4 to your computer and use it in GitHub Desktop.
Ambiguity error with higher order lists and type families
{-# LANGUAGE KindSignatures, DataKinds, TypeFamilies, TypeOperators, GADTs, FlexibleInstances, FlexibleContexts #-}
module Foo where
data HList as where
HNil :: HList '[]
HCons :: a -> HList as -> HList (a ': as)
instance Show (HList '[]) where
show _ = "[]"
instance (Show a, Show (HList as)) => Show (HList (a ': as)) where
show (HCons a as) = show a ++ ":" ++ show as
first :: HList (a ': as) -> HList '[a]
first (HCons a _) = HCons a HNil
newtype Cat a = Cat a
type family MapCat (as :: [*]) :: [*] where
MapCat '[] = '[]
MapCat (a ': as) = Cat a ': MapCat as
type CatList cs = HList (MapCat cs)
first' :: CatList (a ': as) -> CatList '[a]
first' (HCons a _) = HCons a HNil
@CRogers
Copy link
Author

CRogers commented Nov 30, 2014

Couldn't match type ‘MapCat as0’ with ‘MapCat as’
NB: ‘MapCat’ is a type function, and may not be injective
The type variable ‘as0’ is ambiguous
Expected type: CatList (a : as) -> CatList '[a]
  Actual type: CatList (a : as0) -> CatList '[a]
In the ambiguity check for:
  forall a (as :: [*]). CatList (a : as) -> CatList '[a]
To defer the ambiguity check to use sites, enable AllowAmbiguousTypes
In the type signature:
 first' :: CatList (a : as) -> CatList '[a]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment