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,862
    • Issues 4,862
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 455
    • Merge requests 455
  • 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
  • #17535
Closed
Open
Created Dec 02, 2019 by Richard Eisenberg@raeDeveloper

Pattern synonyms allow unlifted top-level bindings -- and they're thunks!

Feeling like being abusive to GHC (and in thinking about https://github.com/ghc-proposals/ghc-proposals/pull/265), I gave it this:

{-# LANGUAGE PatternSynonyms, MagicHash #-}

module Main where

import Debug.Trace
import GHC.Exts

pattern Strange <- 0#
  where Strange = case trace "evaluating now" 0 of
                    I# n -> n

main = do
  putStrLn "Starting"
  print (I# Strange)

Two strange things happened:

  1. This program was accepted, despite the fact that Strange is a top-level unlifted binding.

  2. Strange is actually a thunk. I see Starting in the output before evaluating now.

As I was writing this up, I realized that I probably knew this, deep down, having seen the implementation of this all (where a magical Void# parameter is added to unlifted pattern synonyms). But this should, at least, be documented in the manual, where I could not find it in the pattern synonyms section.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking