Closed mstksg closed 7 years ago
This is a cool idea. I looked on GHC Trac and found that it's already been proposed: https://ghc.haskell.org/trac/ghc/ticket/8779. It's even implemented already: https://phabricator.haskell.org/D2669. (Well, almost implemented and not merged into GHC yet.)
Sometimes pattern synonyms are just alternate total views to a value, and it's a bit misleading when ghc complains that they are potentially not total. Also, if you ever use a pattern synonym as a way to abstract over real constructors, then pattern synonyms not being recognized as total is a total abstraction leakage.
For example:
should basically let you pretend that there's a
State
constructor forState s a
that contains ans -> (a, s)
. For the most part this goes well, except for the fact that if you do pattern match onState
, ghc complains erroneously about an incomplete pattern matchSometimes multiple sets of pattern match can constitute a total match (ie, nil/cons patterns for
Seq
). I think for this we can borrow the same syntax as theMINIMAL
pragma. For example, if we wanted to turnViewL
/ViewR
fromSeq
to be implemented with view patterns, we could do:And we could specify total matches as
MINIMALTOTAL (:<), Nil | (:>), Nil
, maybe?