Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,866
    • Issues 4,866
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 461
    • Merge requests 461
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #3306
Closed
Open
Created Jun 17, 2009 by Simon Peyton Jones@simonpjDeveloper

Improve syntax for GADT + records

This email thread raised the question of defining data constructors that

  • use GADT syntax
  • and record syntax
  • and have class constraints

This combination isn't supported in GHC 6.10, but it's annoying that it isn't. The problem is just coming up with a plausible syntax. Probably the most plausible possibilities are

(A)   data RecContTest a where
         Show a => C { showable :: a } :: RecContTest a

(B)   data RecContTest a where
         C :: Show a => { showable :: a } -> RecContTest a

The latter (B) looks best to me. I dislike (A) because part of the type (the "Show a =>") occurs before the constructor name C, and part appears after. On the other hand, (B) has something that looks vaguely like a type

   { x::ty, y::ty } -> ty

but that's not really valid type syntax. (Mind you, the ! marks in a constructor signature aren't part of valid types either, so maybe it's not so bad to have a special form in constructor declarations.)

But if we were going to adopt (B), then even when there is no class context we should really say

(B)  data RecTest a where
        B :: { arg :: a } -> RecTest a

rather than the current syntax which is

(A)  data RecTest a where
       B { arg :: a } :: RecTest a

[Note the different placement of the double colon and arrow in (B).]

My take on this

  • (B) looks nicer, but it would represent a breaking change
  • But perhaps not many people use record-style syntax + GADT-style syntax
  • And better to make breaking changes sooner than later

Question for everyone:

  • are (A) and (B) the only choices?
  • do you agree (B) is best

There are some replies on the above email thread. Please add further opinions as comments to this ticket.

Edited Mar 09, 2019 by Simon Peyton Jones
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking