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,867
    • Issues 4,867
    • 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
  • #16957
Closed
Open
Created Jul 19, 2019 by Sebastian Graf@sgraf812Developer

COMPLETE sets don't get type-checked

GHC does a bad job at checking whether the ConLikes of a COMPLETE set can actually appear in the same pattern match. Example:

{-# LANGUAGE PatternSynonyms #-}

module Lib where

pattern A :: Maybe Bool
pattern A <- _

pattern B :: Maybe ()
pattern B <- _

{-# COMPLETE A, B #-}

This compiles just fine, whereas I had at least expected a warning. Strange enough the program gets rejected when you remove the Maybe type constructor, so it seems there is some machinery in place which is just not robust enough.

My understanding of a proper fix would try to find a unifying type of all return types. So, starting with a, we want to gradually refine it to Maybe b, then get to know that b ~ Bool, then b ~ () and reject. This would still allow

{-# LANGUAGE PatternSynonyms #-}

module Lib where

pattern A :: Either Bool b
pattern A <- _

pattern B :: Either a ()
pattern B <- _

{-# COMPLETE A, B #-}

f :: Either Bool () -> ()
f A = ()
f B = ()

by inferring the most general unifying type Either Bool () for the COMPLETE pragma.

Edited Jul 19, 2019 by Ryan Scott
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking