1 {-# LANGUAGE FlexibleContexts #-}
3 {-# LANGUAGE MultiParamTypeClasses #-}
4 {-# LANGUAGE OverloadedStrings #-}
5 {-# LANGUAGE TypeFamilies #-}
6 {-# LANGUAGE UndecidableInstances #-}
7 module Language.LOL.Symantic.Type.Int where
9 import Data.Maybe (isJust)
10 import Data.Type.Equality ((:~:)(Refl))
12 import Language.LOL.Symantic.Raw
13 import Language.LOL.Symantic.Type.Common
14 import Language.LOL.Symantic.Type.Fun
15 import Language.LOL.Symantic.Type.Bool
19 data Type_Int (root:: * -> *) h where
20 Type_Int :: Type_Int root Int
21 type instance Root_of_Type (Type_Int root) = root
22 type instance Error_of_Type raw (Type_Int root) = Error_Type_Fun raw
24 -- | Convenient alias.
25 type Type_Fun_Int lam = Type_Root (Type_Cons (Type_Fun lam) Type_Int)
26 -- | Convenient alias.
27 type Type_Fun_Bool_Int lam = Type_Root (Type_Cons (Type_Fun lam) (Type_Cons Type_Bool Type_Int))
29 -- | Convenient alias to include a 'Type_Int' within a type.
30 type_int :: Type_Root_Lift Type_Int root => root Int
31 type_int = type_root_lift Type_Int
34 Type_Eq (Type_Int root) where
35 type_eq Type_Int Type_Int = Just Refl
37 Eq (Type_Int root h) where
38 x == y = isJust $ type_eq x y
39 instance -- Type_from Raw
40 ( Type_Root_Lift Type_Int root
41 , Error_Type_Lift (Error_Type_Fun Raw) (Error_of_Type Raw root)
42 -- NOTE: require UndecidableInstances.
43 ) => Type_from Raw (Type_Int root) where
44 type_from _px_ty raw@(Raw "Int" raws) k =
46 [] -> k $ type_root_lift Type_Int
47 _ -> Left $ Just $ error_type_lift $
48 Error_Type_Fun_Wrong_number_of_arguments 0 raw
49 type_from _px_ty _raw _k = Left Nothing
50 instance -- String_from_Type
51 String_from_Type (Type_Int root) where
52 string_from_type Type_Int = "Int"
54 Show (Type_Int root h) where
55 show = string_from_type