Admin message

Due to a large amount of spam we do not allow new users to create repositories, they are "external" users. If you are a new user and want to create a repository, for example for forking GHC, open a new issue on ghc/ghc using the "get-verified" issue template

generalizing overloaded list syntax to Sized Lists, HLists, HRecords, etc
First, sorry if I've missed an earlier request for this in trac; a few searches did not turn up anything relevant. I've recently taken to doing a lot of work with heterogenous lists (thanks to the DataKinds work) and find the forced-cons-and-nil style of writing lists (e.g. "a:+b:+c:+HN") to be sort of unpleasant. Would it be possible to allow rebinding list-literal syntax? Off the top of my head I think something like the following might be workable, if only I could stop \[\] and (:) from being in scope, even with -XNoImplicitPrelude. (Example requires -XDataKinds -XFlexibleInstances -XGADTs -XMultiParamTypeClasses -XTypeOperators) ``` class HasNil a where ([]) :: a isNil :: a -> Bool class HasCons e l l' | e l -> l', l' -> e l where (:) :: e -> l -> l' uncons :: l' -> Maybe (e,l) -- For homogeneous lists... instance HasNil [a] where ([]) = ([]) isNil = null instance (a ~ a1, a ~ a2) => HasCons a [a1] [a2] where (:) = (:) uncons [] = Nothing uncons (x:xs) = Just (x,xs) -- For HLists... data HList as where HN :: HList '[] (:+) :: a -> HList as -> HList (a ': as) instance HasNil (HList '[]) where ([]) = HN isNil = const True instance (a ~ a1, as ~ as1) => HasCons a (HList as) (HList (a1 ': as1)) where (:) = (:+) uncons (a :+ as) = Just (a,as) ``` <details><summary>Trac metadata</summary> | Trac field | Value | | ---------------------- | -------------- | | Version | 7.6.1 | | Type | FeatureRequest | | TypeOfFailure | OtherFailure | | Priority | normal | | Resolution | Unresolved | | Component | Compiler | | Test case | | | Differential revisions | | | BlockedBy | | | Related | | | Blocking | | | CC | | | Operating system | | | Architecture | | </details> <!-- {"blocked_by":[],"summary":"Rebindable list syntax?","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"7.6.1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"FeatureRequest","description":"First, sorry if I've missed an earlier request for this in trac; a few searches did not turn up anything relevant.\r\n\r\nI've recently taken to doing a lot of work with heterogenous lists (thanks to the DataKinds work) and find the forced-cons-and-nil style of writing lists (e.g. \"a:+b:+c:+HN\") to be sort of unpleasant.\r\n\r\nWould it be possible to allow rebinding list-literal syntax? Off the top of my head I think something like the following might be workable, if only I could stop [] and (:) from being in scope, even with -XNoImplicitPrelude. (Example requires -XDataKinds -XFlexibleInstances -XGADTs -XMultiParamTypeClasses -XTypeOperators)\r\n\r\n{{{\r\nclass HasNil a where\r\n ([]) :: a\r\n isNil :: a -> Bool\r\n\r\nclass HasCons e l l' | e l -> l', l' -> e l where\r\n (:) :: e -> l -> l'\r\n uncons :: l' -> Maybe (e,l)\r\n\r\n-- For homogeneous lists...\r\ninstance HasNil [a] where\r\n ([]) = ([])\r\n isNil = null\r\n\r\ninstance (a ~ a1, a ~ a2) => HasCons a [a1] [a2] where\r\n (:) = (:)\r\n uncons [] = Nothing\r\n uncons (x:xs) = Just (x,xs)\r\n\r\n-- For HLists...\r\ndata HList as where\r\n HN :: HList '[]\r\n (:+) :: a -> HList as -> HList (a ': as)\r\n\r\ninstance HasNil (HList '[]) where\r\n ([]) = HN\r\n isNil = const True\r\n\r\ninstance (a ~ a1, as ~ as1) => HasCons a (HList as) (HList (a1 ': as1)) where\r\n (:) = (:+)\r\n uncons (a :+ as) = Just (a,as)\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->
issue