1
1
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:
Rob Rix 2019-10-08 15:10:33 -04:00
parent 4e194a5943
commit a307d0757a
No known key found for this signature in database
GPG Key ID: F188A01508EA1CF7

View File

@ -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