Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
GHC
GHC
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,388
    • Issues 4,388
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 374
    • Merge Requests 374
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #7495

Closed
Open
Opened Dec 10, 2012 by nwf@trac-nwf

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)
Trac metadata
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
Edited Mar 09, 2019 by Carter Schonwald
Assignee
Assign to
8.0.1
Milestone
8.0.1 (Past due)
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#7495