mirror of
https://github.com/github/semantic.git
synced 2024-12-26 00:12:29 +03:00
Define a pattern synonym for matching out of sums.
This commit is contained in:
parent
4e194a5943
commit
a307d0757a
@ -1,6 +1,7 @@
|
||||
{-# LANGUAGE AllowAmbiguousTypes, DataKinds, FlexibleInstances, MultiParamTypeClasses, ScopedTypeVariables, TypeApplications, TypeFamilies, TypeOperators, UndecidableInstances #-}
|
||||
{-# LANGUAGE AllowAmbiguousTypes, DataKinds, FlexibleInstances, MultiParamTypeClasses, PatternSynonyms, ScopedTypeVariables, TypeApplications, TypeFamilies, TypeOperators, UndecidableInstances, ViewPatterns #-}
|
||||
module AST.Element
|
||||
( Element(..)
|
||||
, pattern Prj
|
||||
) where
|
||||
|
||||
import GHC.Generics
|
||||
@ -15,6 +16,10 @@ instance (Element' elem sub sup, elem ~ Elem sub sup) => Element sub sup where
|
||||
prj = prj' @elem
|
||||
|
||||
|
||||
pattern Prj :: Element sub sup => sub a -> sup a
|
||||
pattern Prj sub <- (prj -> Just sub)
|
||||
|
||||
|
||||
type family Elem sub sup where
|
||||
Elem t t = 'True
|
||||
Elem t (l :+: r) = Elem t l || Elem t r
|
||||
|
Loading…
Reference in New Issue
Block a user