Opened 2 weeks ago

Last modified 2 weeks ago

#14423 new feature request

{-# complete #-} should be able to handle | like {-# minimal #-}

Reported by: ekmett Owned by:
Priority: normal Milestone:
Component: Compiler (Type checker) Version: 8.2.1
Keywords: PatternSynonyms Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: 8779 Differential Rev(s):
Wiki Page:

Description

It'd be really convenient to be able to specify these like we can with minimal pragmas, mixing ands and ors. I wind up with a combinatorial explosion of such annotations for the cases where it works when I have large numbers of patterns.

I have at least one use case where something that would be a trivial pattern to express with one (complicated) expression involving | becomes 64 lines of complete pragmas, and every time I extend it this count doubles.

Consider what happens if you add a mix of actual and smart views of a data type:

{-# language ViewPatterns, PatternSynonyms, GeneralizedNewtypeDeriving #-}

newtype Delta = Delta Int deriving (Eq,Num)

instance Monoid Delta where
  mempty = 0
  mappend = (+)

data Exp = Var !Int | AP !Delta !Exp !Exp | LAM !Delta !Exp

rel 0 xs = xs
rel d (AP d' l r) = AP (d + d') l r
rel d (LAM d' b) = LAM (d + d') b
rel _ (Var n) = Var n

pattern Ap a b <- AP d (rel d -> a) (rel d -> b) where
  Ap a b = AP 0 a b

pattern Lam b <- LAM d (rel d -> b) where
  Lam b = LAM 0 b

{-# complete Var, AP, Lam #-}
{-# complete Var, Ap, LAM #-}
{-# complete Var, AP, LAM #-}

Every data constructor I add with a smart view adds to the powerset of complete pragmas I should supply.

On the other hand with | patterns:

{-# complete Var, (Ap | AP), (Lam | LAM) #-}

extends linearly.

Change History (1)

comment:1 Changed 2 weeks ago by simonpj

Keywords: PatternSynonyms added
Note: See TracTickets for help on using tickets.