Skip to content
Snippets Groups Projects
Forked from Glasgow Haskell Compiler / GHC
5508 commits behind the upstream repository.
  • Vladislav Zavialov's avatar
    8168b42a
    Whitespace-sensitive bang patterns (#1087, #17162) · 8168b42a
    Vladislav Zavialov authored
    This patch implements a part of GHC Proposal #229 that covers five
    operators:
    
    * the bang operator (!)
    * the tilde operator (~)
    * the at operator (@)
    * the dollar operator ($)
    * the double dollar operator ($$)
    
    Based on surrounding whitespace, these operators are disambiguated into
    bang patterns, lazy patterns, strictness annotations, type
    applications, splices, and typed splices.
    
    This patch doesn't cover the (-) operator or the -Woperator-whitespace
    warning, which are left as future work.
    8168b42a
    History
    Whitespace-sensitive bang patterns (#1087, #17162)
    Vladislav Zavialov authored
    This patch implements a part of GHC Proposal #229 that covers five
    operators:
    
    * the bang operator (!)
    * the tilde operator (~)
    * the at operator (@)
    * the dollar operator ($)
    * the double dollar operator ($$)
    
    Based on surrounding whitespace, these operators are disambiguated into
    bang patterns, lazy patterns, strictness annotations, type
    applications, splices, and typed splices.
    
    This patch doesn't cover the (-) operator or the -Woperator-whitespace
    warning, which are left as future work.
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
proposal-229e.hs 474 B
{-# LANGUAGE BangPatterns #-}

module Proposal229e ((!), f) where

(!) :: Maybe a -> a -> (a, a)
f :: a -> a

-- the preceding '}' is not from a comment,
-- so (!) is tight infix (therefore an operator)
Nothing{}!x = (x, x)

-- the following '{' opens a multi-line comment,
-- so (!) is loose infix (therefore an operator)
Just a !{-comment-}x = (a, x)

-- the preceding '}' is closing a multi-line comment,
-- so (!) is prefix (therefore a bang pattern)
f{-comment-}!x = x