1 {-# LANGUAGE DataKinds #-}
2 {-# LANGUAGE TypeFamilies #-}
3 {-# LANGUAGE TypeOperators #-}
4 {-# LANGUAGE UndecidableInstances #-}
5 module Language.Symantic.Type.Alt where
7 import Language.Symantic.Type.Root
10 -- | Type making an alternative between two types.
11 data Type_Alt curr next (root:: * -> *) h
12 = Type_Alt_Curr (curr root h)
13 | Type_Alt_Next (next root h)
14 -- | Convenient alias. Requires @TypeOperators@.
17 type instance Root_of_Type (Type_Alt curr next root) = root
19 -- * Type family 'Is_Last_Type'
20 -- | Return whether a given type is the last one in a given type stack.
22 -- NOTE: each type parser uses this type family
23 -- when it encounters unsupported syntax:
24 -- to know if it is the last type parser component that will be tried
25 -- (and thus return 'Error_Type_Unsupported')
26 -- or if some other type parser component shall be tried
27 -- (and thus return 'Error_Type_Unsupported_here',
28 -- which is then handled accordingly by the 'Type0_From' instance of 'Type_Alt').
29 type family Is_Last_Type (ty:: * -> *) (tys:: * -> *) :: Bool where
30 Is_Last_Type ty ty = 'True
31 Is_Last_Type ty (Type_Root tys) = Is_Last_Type ty (tys (Type_Root tys))
32 Is_Last_Type (ty root) (Type_Alt ty next root) = 'False
33 Is_Last_Type other (Type_Alt curr next root) = Is_Last_Type other (next root)
36 -- | A discarded type.
37 data No_Type (root:: * -> *) h