Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Register
  • Sign in
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
    • Locked files
  • Issues 5.5k
    • Issues 5.5k
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 629
    • Merge requests 629
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Artifacts
    • Schedules
    • Test cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • 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 CompilerGlasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #4148
Closed
Open
Issue created Jun 23, 2010 by guest@trac-guest

improve new recursive do syntax

This is a request for an adjustment of the syntax for the new recursive do notation. "rec { ... }" should parse/type check as an expression such that:

  mdo
      a <- getChar
      b <- f c
      c <- g b
      putChar c
      return b

can be written as

  do rec
      a <- getChar
      b <- f c
      c <- g b
      putChar c
      return b

at moment the closest you can get is ...

t5 =
  do rec   
      a <- getChar
      b <- f c
      c <- g b
      putChar c
    return b 

it seems rec { ... } is a binding construct not an expression and therefore can not be used in the final position (or sole component) of a do block

benefits

  • drop in replacement for mdo, that is the construct "do rec"

becomes semantically and syntactically equivalent to the mdo notation

  • current layout is maintained (which is much neater)
  • I would argue that it is more intuitive

dificulty

  • it seems to be a minor change?.

related

  • this change seems to have been introduced as

http://hackage.haskell.org/trac/ghc/ticket/2798 somewhat surreptitiously (well, cought me by surprise, anyway.).

background

  1. 12.1 introduced a change to the recursive do syntax

http://old.nabble.com/Update-on-GHC-6.12.1-td26103595.html

Instead of writing

  mdo
    a <- getChar
    b <- f c
    c <- g b
    putChar c
    return b

you would write

  do
    a <- getChar
    rec { b <- f c
          ; c <- g b }
    putChar c
    return b

A couple of issues about the change:

  • the new syntax spoils layout (see above)
  • migrating to the new syntax with the current limitation is

non-trivial, requires analysis of code (in some cases).

for the record ...

> t2 =
>  do rec
>       a <- getChar
>       b <- f c
>       c <- g b
>       putChar c
>       return b

> f = return . (const 'a')
> g = return

eg.lhs:23:6:
    The last statement in a 'do' construct must be an expression
Failed, modules loaded: none.
Trac metadata
Trac field Value
Version 6.12.3
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC jvlask@hotmail.com
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking